//
//  GCAVPlayer.m
//  GC_OC
//
//  Created by 叶建辉 on 2022/6/9.
//
#import "GCAVPlayer.h"
#import "UIView+Frame.h"
#import "TYDownLoadDataManager.h"
#import "TYDownLoadUtility.h"
#import "GCWordLabel.h"
@protocol wordcellDelegate <NSObject>

-(void)slidingDirection;
-(void)clickWithTag:(NSInteger)tag;

@end

@interface wordcell : UITableViewCell

@property(nonatomic,weak)id<wordcellDelegate>delegate;

@property(nonatomic,strong)NSString *resStr;
@property(nonatomic,strong)NSString *timeStr;
@property(nonatomic,strong)GCWordLabel *nameLab;
@property(nonatomic,strong)GCWordLabel *nameLab1;
@property(nonatomic,assign)NSInteger selectnum;
@property(nonatomic,assign)BOOL isShow;
@end

@interface wordcell ()

#define gc_fontf  LYRICSH*.4
#define showfontf  LYRICSH*.4
@property(nonatomic,assign)int gc_num;
@property(nonatomic,strong)NSTimer *gctimer;
@property(nonatomic,assign)CGPoint startP;
@property(nonatomic,assign)CGPoint endP;
@end

@implementation wordcell

-(void)setIsShow:(BOOL)isShow{
    _isShow = isShow;
    
//    if (!_isShow) {
//        _resStr = [NSString stringWithFormat:@"        %@",_resStr];
//    }else{
//        _resStr = [[_resStr componentsSeparatedByString:@"        "] lastObject];
//    }
    
    NSArray *arrs = [toolHelp get32String:_resStr andFont:_isShow ? showfontf:gc_fontf];
    NSString *a = [arrs firstObject];
    NSString *b = [arrs lastObject];
    if (b.length == 0) {
        _nameLab.text = _resStr;
    }else{
        _nameLab.text = a;
        _nameLab1.text = b;
    }
    [self setNeedsLayout];
}

-(void)setResStr:(NSString *)resStr{
    _resStr = [NSString stringWithFormat:@"        %@",resStr];;
    if (_resStr.length>0) {
        NSArray *arrs = [toolHelp get32String:_resStr andFont:gc_fontf];
        NSString *a = [arrs firstObject];
        NSString *b = [arrs lastObject];
        if (b.length == 0) {
            _nameLab.text = _resStr;
        }else{
            _nameLab.text = a;
            _nameLab1.text = b;
        }
        [self setNeedsLayout];
    }
}


-(GCWordLabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [GCWordLabel new];
        _nameLab.backgroundColor = [UIColor clearColor];
        _nameLab.textColor = [UIColor colorWithWhite:1 alpha:.1];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.numberOfLines = 0;
        _nameLab.blendColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
    }
    return _nameLab;
}

-(GCWordLabel *)nameLab1{
    if (!_nameLab1) {
        _nameLab1 = [GCWordLabel new];
        _nameLab1.backgroundColor = [UIColor clearColor];
        _nameLab1.textColor = [UIColor colorWithWhite:1 alpha:.1];
        _nameLab1.textAlignment = NSTextAlignmentLeft;
        _nameLab1.numberOfLines = 0;
        _nameLab1.blendColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
    }
    return _nameLab1;
}

-(void)setSelectnum:(NSInteger)superIndex{
    _selectnum = superIndex;
    
}

-(void)setTimeStr:(NSString *)timeStr{
    _timeStr = timeStr;
    
//    NSString *timestr = [[_timeStr componentsSeparatedByString:@"-"] firstObject];
//    _skipf = timestr.floatValue;
//    float timef = [[NSString stringWithFormat:@"%.0lf",[timestr floatValue]] floatValue];
    
//    NSString *timeStrend = [toolHelp timeFormatted:timef];
//    UIView *playBv = [_playView viewWithTag:200];
//    UILabel *timeLab = [playBv viewWithTag:300];
//    timeLab.text = timeStrend;
//    [self setNeedsLayout];
//    NSLog(@"timef~~>>%@",timeStrend);
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.nameLab];
        [self addSubview:self.nameLab1];
        
        _gc_num = 0;
        
    }
    return self;
}


-(void)clickself{
    if ([self.delegate respondsToSelector:@selector(clickWithTag:)]) {
        [self.delegate clickWithTag:self.tag];
    }
    
    NSLog(@"~~~~~~~~~>>%zd",self.tag);
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    if (_resStr.length>0) {
        NSArray *arrs = [toolHelp get32String:_resStr andFont:_isShow?showfontf:gc_fontf];
        NSString *b = [arrs lastObject];
        if (b.length == 0) {
            _nameLab.frame = CGRectMake(WIDTHDiv*.05, 0, WIDTHDiv*.95, LYRICSH);
            [_nameLab setFont:_isShow?[UIFont systemFontOfSize:showfontf]:[UIFont systemFontOfSize:gc_fontf]];
            _nameLab1.hidden = YES;
        }else{
            _nameLab1.hidden = NO;
            _nameLab.frame = CGRectMake(WIDTHDiv*.05, 0, WIDTHDiv*.95, LYRICSH*.5);
            [_nameLab setFont:_isShow?[UIFont systemFontOfSize:showfontf]:[UIFont systemFontOfSize:gc_fontf]];
            _nameLab1.frame = CGRectMake(WIDTHDiv*.05, LYRICSH*.5, WIDTHDiv*.95, LYRICSH*.5);
            [_nameLab1 setFont:_isShow?[UIFont systemFontOfSize:showfontf]:[UIFont systemFontOfSize:gc_fontf]];
        }
    }
    
    
    
}

-(void)dealloc{
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _startP = [t locationInView:self];
    _gctimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(gctimerchange) userInfo:nil repeats:YES];
}

-(void)gctimerchange{
    _gc_num++;
}


-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _endP = [t locationInView:self];
    [self changemove];
}

-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _endP = [t locationInView:self];
    [self changemove];
}



-(void)changemove{
    [_gctimer invalidate];
    if (_gc_num>50) {
        _gc_num=0;
        [self clickself];
        
        return;
    }
    CGFloat x = _startP.x - _endP.x;
    
    CGFloat y = _startP.y - _endP.y;
    
    if (fabs(x)>fabs(y)) {
        if (fabs(x)>20) {
            if (x<0) {
                if ([self.delegate respondsToSelector:@selector(slidingDirection)]) {
                    [self.delegate slidingDirection];
                }
            }else{
                [self clickself];
            }
        }else{
            [self clickself];
        }
    }else{
        [self clickself];
    }
}

@end


@protocol wordViewDelegate <NSObject>

//-(void)ClickOnTheIndexPathRow:(NSInteger)row;

-(void)wslidingDirection;

-(void)wslierChange:(float)progress;

-(void)wmoveslier:(BOOL)ismoveslier;

-(void)beishuclick:(NSString *)str;

@end

@interface wordView : UIView

@property(nonatomic,weak)id <wordViewDelegate>delegate;

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UIView *playconView;
@property(nonatomic,strong)NSMutableArray *datas;

@property(nonatomic,assign)NSInteger selectNum;

@property(nonatomic,assign)BOOL sliding;

@property(nonatomic,assign)int wordTag;
@property(nonatomic,assign)int wordindex;
@property(nonatomic,assign)int wordchage;
@property(nonatomic,assign)int wordskipindex;

@property(nonatomic,strong)NSMutableArray *timeDatas;

@property(nonatomic,strong)NSTimer *timer;
@property(nonatomic,assign)int timernum;
-(void)updatePlayerTime:(float)time;
-(void)updateLry;
@property(nonatomic,assign)BOOL isShow;
@property(nonatomic,strong)UIView *playView;
@property(nonatomic,weak)UILabel *timeLab;
@property(nonatomic,weak)UIButton *playBtn;
@end

@interface wordView ()<UITableViewDataSource,UITableViewDelegate,wordcellDelegate,UIScrollViewDelegate,JHPropressViewDelegate,GCAVPlayerDelegate>
@property(nonatomic,assign)BOOL isFirstShow;
@property(nonatomic,assign)BOOL isOne;
@property(nonatomic,assign)float onef;
@property(nonatomic,assign)float twof;
@property(nonatomic,assign)int median;
@property(nonatomic,assign)NSInteger curindex;
@property(nonatomic,assign)NSInteger lastindex;
@property(nonatomic,strong)JHPropressView *slider;
@property(nonatomic,assign)float skipf;

@end

@implementation wordView

-(UIView *)playView{
    if (!_playView) {
        _playView = [UIView new];
//        _playView.hidden = YES;
        UILabel *xianLab = [UILabel new];
        xianLab.backgroundColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
        xianLab.textColor = [UIColor whiteColor];
        xianLab.tag = 100;
        [_playView addSubview:xianLab];
        
        UIView *playBv = [UIView new];
        playBv.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
        playBv.tag = 200;
        [_playView addSubview:playBv];
        
        UILabel *timeLab = [UILabel new];
        timeLab.backgroundColor = [UIColor clearColor];
        timeLab.textColor = [UIColor whiteColor];
        timeLab.tag = 300;
        [playBv addSubview:timeLab];
        _timeLab = timeLab;
        
        UIButton *playbp = [UIButton new];
        [playbp setImage:[UIImage br_svgImageNamed:@"icon_播放_32_defaultm备份_2"] forState:UIControlStateNormal];
        playbp.tag = 400;
        [playbp addTarget:self action:@selector(playbpClick) forControlEvents:UIControlEventTouchUpInside];
        [playBv addSubview:playbp];
        
    }
    return _playView;
}

-(NSArray *)getTimeWithPlayerTime:(float)playtime{
    NSString *timestr = [NSString stringWithFormat:@"%.1lf",playtime/10];
    NSMutableArray *as = [NSMutableArray array];
    for (int i = 0; i < _timeDatas.count; i++) {
        float a1 = [[[_timeDatas[i] componentsSeparatedByString:@"-"] firstObject] floatValue];
        float a2 = [[[_timeDatas[i] componentsSeparatedByString:@"-"] lastObject] floatValue];
        if ([timestr floatValue]>a1 && [timestr floatValue] < a2) {
            [as addObject:@(a1)];
            [as addObject:@(i)];
            [as addObject:@(a2)];
            break;
        }
    }
    return as.copy;
}

-(void)updatePlayerTime:(float)time{
    
    NSInteger timeint = (NSInteger)time;
    if (timeint%10 == 0) {
        for (int i = 0; i < 2; i++) {
            _slider.press = timeint/10/[GCAVPlayer shared].videoLength;
            UILabel *lab = [_playconView viewWithTag:50+i];
            lab.text = i == 0?[toolHelp timeFormatted:(int)timeint/10]:[toolHelp timeFormatted:(int)[GCAVPlayer shared].videoLength];
        }
    }
    
    _timernum++;
    if (_timernum == 30) {
        _sliding = NO;
        _playView.hidden = YES;
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:.2 animations:^{
                [self->_tableView setContentOffset:CGPointMake(0, LYRICSH*self->_wordskipindex) animated:NO];
            }completion:^(BOOL finished) {
                self->_sliding = NO;
                [self updateCellshow];
            }];
        });
    }
//    if (_timernum == 60) {
//        _playView.hidden = YES;
//    }
    NSArray *ass = [self getTimeWithPlayerTime:time];
    if (ass.count>0) {
        float a1 = [[ass firstObject] floatValue];
        float a2 = [[ass lastObject] floatValue];
        _wordTag = [ass[1] intValue];
        _wordskipindex = [ass[1] intValue];
        NSString *timestr = [NSString stringWithFormat:@"%.1lf",time/10];
//        NSLog(@"1111time -->%@ --->>%d",timestr,_wordskipindex);
        if ([timestr floatValue]>a1) {
            wordcell * cell = (wordcell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:_wordTag]];
            float b = (a2-a1)*10;
            float c = 1/b;
            _wordindex++;
            if (_isFirstShow) {
                _isFirstShow = NO;
                cell.isShow = YES;
                NSArray *aa = [toolHelp get32String:cell.resStr andFont:showfontf];
                NSString *bb = [aa firstObject];
                NSString *cc = [aa lastObject];
                _isOne = cc.length>0?NO:YES;
                if (!_isOne) {
                    _onef = (float)bb.length/(float)cell.resStr.length;
                    _twof = (float)cc.length/(float)cell.resStr.length;
                    _onef = b*_onef;
                    _twof = b*_twof;
                    _median = _onef;
                    _onef = 1/_onef;
                    _twof = 1/_twof;
                }
            }
            if (_isOne) {
                cell.nameLab.colorRatio = (float)_wordindex*c;
                cell.nameLab.textColor = [UIColor whiteColor];
            }else{
                if (_wordindex<=_median) {
                    cell.nameLab.colorRatio = (float)_wordindex*_onef;
                }else{
                    cell.nameLab1.colorRatio = (float)(_wordindex-_median-1)*_twof;
                }
                cell.nameLab.textColor = [UIColor whiteColor];
                cell.nameLab1.textColor = [UIColor whiteColor];
            }
            if ([timestr floatValue]+.2>a2) {
                _isFirstShow = YES;
                cell.isShow = NO;
                cell.nameLab.colorRatio = 0;
                cell.nameLab1.colorRatio = 0;
                cell.nameLab.textColor = [UIColor colorWithWhite:1 alpha:.5];
                cell.nameLab1.textColor = [UIColor colorWithWhite:1 alpha:.5];
                _wordTag++;
                _wordindex=0;
            }
        }
        if (_wordchage != _wordTag) {
            _wordchage = _wordTag;
            if (!_sliding) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [UIView animateWithDuration:.2 animations:^{
                        [self->_tableView setContentOffset:CGPointMake(0, LYRICSH*self->_wordskipindex) animated:NO];
                    }completion:^(BOOL finished) {
                        self->_sliding = NO;
                        [self updateCellshow];
                    }];
                });
            }
        }
    }
}

-(void)updateCellshow{
    NSArray *cells = [_tableView indexPathsForVisibleRows];
    if (cells.count>4) {
        NSIndexPath *path = cells[4];
        NSString *timestr = [[_timeDatas[path.section] componentsSeparatedByString:@"-"] firstObject];
        float timef = timestr.floatValue;
        _skipf = timef;
        NSString *labtimestr = [toolHelp timeFormatted:timef];
        _timeLab.text = labtimestr;
        [self setNeedsLayout];
    }
    
    for (int i = 0; i < cells.count; i++) {
        wordcell *cell = [_tableView cellForRowAtIndexPath:cells[i]];
        if (i == 0 || i == cells.count-2) {
            cell.nameLab.textColor = [UIColor colorWithWhite:1 alpha:.5];
            cell.nameLab1.textColor = [UIColor colorWithWhite:1 alpha:.5];
        }else if (i == cells.count-1) {
            cell.nameLab.textColor = [UIColor colorWithWhite:1 alpha:.25];
            cell.nameLab1.textColor = [UIColor colorWithWhite:1 alpha:.25];
        }else{
            cell.nameLab.textColor = [UIColor colorWithWhite:1 alpha:.9];
            cell.nameLab1.textColor = [UIColor colorWithWhite:1 alpha:.9];
        }
    }
}

-(void)slidingDirection{
    if ([self.delegate respondsToSelector:@selector(wslidingDirection)]) {
        [self.delegate wslidingDirection];
    }
}

-(void)setDatas:(NSMutableArray *)LabTitleStrs{
    _datas = LabTitleStrs;
    [_tableView reloadData];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.datas.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return .0001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return .0001;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

-(void)clickWithTag:(NSInteger)tag{
//    _curindex = tag;
//    wordcell * cell = (wordcell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:_curindex]];
//    cell.playView.hidden = NO;
//    cell.playbp.hidden = NO;
//
//    wordcell * cell1 = (wordcell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:_lastindex]];
//    cell1.playView.hidden = YES;
//    cell1.playbp.hidden = YES;
//
//    if (_lastindex == _curindex) {
//        wordcell * cell = (wordcell *)[_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:_curindex]];
//        cell.playView.hidden = NO;
//        cell.playbp.hidden = NO;
//    }
//
//    _lastindex = _curindex;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return LYRICSH;
}

static NSString *wordCellIdentifier = @"CELL";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    wordcell *cell = [[wordcell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:wordCellIdentifier];
    cell.tag = indexPath.section;
    cell.selectnum = _selectNum;
    cell.timeStr = _timeDatas[indexPath.section];
    cell.resStr = _datas[indexPath.section];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    
    return cell;
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    _tableView.contentSize = CGSizeMake(WIDTHDiv, LYRICSH*(_datas.count+3));
    _sliding = YES;
    [self updateCellshow];
    
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
    _playView.hidden = NO;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    _timernum = 0;
}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (!decelerate) {
        _timernum = 0;
    }
}

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
    }
    return _tableView;
}

- (void)returnPress:(float)sliderValue andIscache:(BOOL)isCache{
    if ([self.delegate respondsToSelector:@selector(wslierChange:)]) {
        [self.delegate wslierChange:sliderValue];
    }
}

- (void)returnBegan:(BOOL)isMove andIscache:(BOOL)isCache{
    if ([self.delegate respondsToSelector:@selector(wmoveslier:)]) {
        [self.delegate wmoveslier:isMove];
    }
}

-(UIView *)playconView{
    if (!_playconView) {
        _playconView = [UIView new];
//        _playconView.backgroundColor = [UIColor redColor];
        _slider = [JHPropressView new];
        _slider.delegate = self;
        _slider.isCache = YES;
        _slider.jhImage = [UIImage imageNamed:@"gc_slider"];
        [_playconView addSubview:_slider];
        
        for (int i = 0; i < 2; i++) {
            UILabel *lab = [UILabel new];
            lab.textColor = [UIColor colorWithWhite:.95 alpha:1];
//            lab.backgroundColor = [UIColor greenColor];
            lab.tag = 50+i;
            if (i == 0) {
                lab.textAlignment = NSTextAlignmentLeft;
            }else{
                lab.textAlignment = NSTextAlignmentRight;
            }
            [_playconView addSubview:lab];
            
            UIButton *btn = [UIButton new];
            btn.tag = 60+i;
//            btn.backgroundColor = [UIColor greenColor];
//            float btnwh = WIDTHDiv*.1;
            if (i == 0) {
                [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@",[NSString stringWithFormat:@"%.1lf",[[[NSUserDefaults standardUserDefaults] valueForKey:@"playbeishu"] floatValue]]]] forState:UIControlStateNormal];
            }else{
                [btn setImage:[UIImage imageNamed:@"narrow_playBtn_puse"] forState:UIControlStateNormal];
                _playBtn = btn;
            }
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            [_playconView addSubview:btn];
        }
        
       
    }
    return _playconView;
}

-(void)btnClick:(UIButton *)sender{
    if (sender.tag- 60 == 0) {
        PlayMulitplePopView *view = [[PlayMulitplePopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        view.mulitBlock = ^(NSString * _Nonnull mulit) {
            [GCAVPlayer shared].player.rate = mulit.floatValue;
            [sender setImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@", mulit]] forState:UIControlStateNormal];
            [[NSUserDefaults standardUserDefaults] setValue:mulit forKey:@"playbeishu"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            if ([self.delegate respondsToSelector:@selector(beishuclick:)]) {
                [self.delegate beishuclick:mulit];
            }
        };
        
        [view showIn:[[[UIApplication sharedApplication] delegate] window] currentMulitple:[NSString stringWithFormat:@"%f",[GCAVPlayer shared].player.rate]];
    }else{
        [GCAVPlayer shared].player.rate == 0?[[GCAVPlayer shared] play]:[[GCAVPlayer shared] pause];
    }
}

-(void)cacheProgress:(float)cp playProgress:(float)pp{
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _tableView.frame = CGRectMake(0, LYRICSH*.5, self.frame.size.width, LYRICSH*10);
    
    _playconView.frame = CGRectMake(0, self.zf_height-LYRICSH*1.3, WIDTHDiv, LYRICSH*1.2);
    
    _slider.frame = CGRectMake(WIDTHDiv*.1, 0, WIDTHDiv*.6, _playconView.zf_height*.3);
    
    for (int i = 0; i < 2; i++) {
        UILabel *lab = [_playconView viewWithTag:50+i];
        lab.frame = CGRectMake(WIDTHDiv*.1+i*WIDTHDiv*.35, _slider.zf_bottom+WIDTHDiv*.02, WIDTHDiv*.25, _playconView.zf_height*.4);
        
        float btnwh = 0.03*WIDTHDiv+.02*HEIGHTDiv;
        UIButton *btn = [_playconView viewWithTag:60+i];
        btn.frame = CGRectMake(WIDTHDiv- (2-i)*WIDTHDiv*.12, (_playconView.zf_height-btnwh)/2, btnwh, btnwh);
    }
    
    
    _playView.frame = CGRectMake(0, LYRICSH*4, WIDTHDiv, LYRICSH);
    UILabel *xianLab = [_playView viewWithTag:100];
    UIView *playBv = [_playView viewWithTag:200];
    UILabel *timeLab = [playBv viewWithTag:300];
    CGSize size = [[NSString stringWithFormat:@"%@:",timeLab.text] sizeWithFont:[UIFont systemFontOfSize:LYRICSH*.3] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    xianLab.frame = CGRectMake(WIDTHDiv*.05, LYRICSH*.49, WIDTHDiv*.95-size.width-LYRICSH*.6, LYRICSH*.04);
    playBv.frame = CGRectMake(xianLab.zf_right, LYRICSH*.25, size.width+LYRICSH*.55, LYRICSH*.5);
    playBv.layer.cornerRadius =  playBv.zf_height/2;
    playBv.layer.masksToBounds = YES;
    timeLab.frame = CGRectMake(LYRICSH*.075, LYRICSH*.05, size.width, LYRICSH*.4);
    timeLab.font = [UIFont systemFontOfSize:LYRICSH*.3];
    UIButton *playbp = [playBv viewWithTag:400];
    playbp.frame = CGRectMake(timeLab.zf_right, LYRICSH*.025, LYRICSH*.45, LYRICSH*.45);
        
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _sliding = NO;
        _isOne = YES;
        _isFirstShow = YES;
        _wordTag = 0;
        _wordindex = 0;
        _curindex = 0;
        _lastindex = 0;
        self.backgroundColor = [UIColor clearColor];
        _datas = [NSMutableArray array];
        _timeDatas = NSMutableArray.array;
        [self addSubview:self.tableView];
        [self addSubview:self.playconView];
        [self addSubview:self.playView];
        
        [self updateLry];
        
    }
    return self;
}

-(void)updateLry{
    [NSTimer scheduledTimerWithTimeInterval:.1 repeats:NO block:^(NSTimer * _Nonnull timer) {
        [self updateCellshow];
    }];
}

-(void)playbpClick{
    [[GCAVPlayer shared] seekToTime:_skipf completionHandler:^(BOOL finished) {
        self->_playView.hidden = YES;
    }];
}

@end


@protocol OrderViewCellDelegate <NSObject>

-(void)slidingDirection;
-(void)clickWithTag:(NSInteger)tag;

@end

@interface listCell : UITableViewCell

@property(nonatomic,weak)id<OrderViewCellDelegate>delegate;

@property(nonatomic,strong)NSDictionary *resDic;

@property(nonatomic,assign)NSInteger selectnum;

@end

@interface listCell ()

@property(nonatomic,strong)UILabel *nameLab;

@property(nonatomic,strong)UILabel *timeLab;

@property(nonatomic,strong)UIImageView *arrowImg;

@property(nonatomic,assign)int gc_num;
@property(nonatomic,strong)NSTimer *gctimer;
@property(nonatomic,assign)CGPoint startP;
@property(nonatomic,assign)CGPoint endP;

@end

@implementation listCell

-(UILabel *)nameLab{
    if (!_nameLab) {
        _nameLab = [UILabel new];
        _nameLab.textColor = [UIColor colorWithWhite:1 alpha:1];
        _nameLab.textAlignment = NSTextAlignmentLeft;
    }
    return _nameLab;
}

-(UILabel *)timeLab{
    if (!_timeLab) {
        _timeLab = [UILabel new];
        _timeLab.textColor = [UIColor colorWithWhite:1 alpha:1];
//        _timeLab.textAlignment = NSTextAlignmentRight;
    }
    return _timeLab;
}

-(UIImageView *)arrowImg{
    if (!_arrowImg) {
        _arrowImg = [UIImageView new];
//        _arrowImg.backgroundColor = [UIColor greenColor];
        _arrowImg.image = [UIImage br_svgImageNamed:@"icon_播放_32_defaultm备份_2"];
    }
    return _arrowImg;
}

-(void)setSelectnum:(NSInteger)superIndex{
    _selectnum = superIndex;
    
}

-(void)setResDic:(NSDictionary *)resDic{
    _resDic = resDic;
    _nameLab.text = [NSString setSafeString:_resDic[@"name"]];
    _timeLab.text = [NSString setSafeString:_resDic[@"video_num"]];
    if (_timeLab.text.intValue == 0) {
        _timeLab.text = @"暂无视频";
    }else{
        _timeLab.text = [self getVideoLengthFromTimeLength:[_timeLab.text floatValue]];
    }
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.nameLab];
        [self addSubview:self.timeLab];
        [self addSubview:self.arrowImg];
        _gc_num = 0;
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
//    HEIGHTDiv*.035+WIDTHDiv*.035
    _arrowImg.frame = CGRectMake(self.zf_height*.2, self.zf_height*.25, self.zf_height*.5, self.zf_height*.5);
    
    
    
    CGSize titleSize = [@"00:000" sizeWithFont:[UIFont systemFontOfSize:_timeLab.zf_height*.3] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
    
    _timeLab.frame = CGRectMake(self.zf_width-titleSize.width, 0, titleSize.width, self.zf_height);
    _timeLab.font = [UIFont systemFontOfSize:_timeLab.zf_height*.3];
    
    _nameLab.frame = CGRectMake(self.zf_height*.9, 0, self.zf_width-self.zf_height*.9-titleSize.width, self.zf_height);
    _nameLab.font = [UIFont systemFontOfSize:_nameLab.zf_height*.4];
    
    
    if (_selectnum == self.tag) {
        _arrowImg.hidden = NO;
        _nameLab.font = [UIFont boldSystemFontOfSize:_nameLab.zf_height*.425];
//        _nameLab.textColor = [UIColor whiteColor];
    }else{
        _arrowImg.hidden = YES;
        _nameLab.font = [UIFont systemFontOfSize:_nameLab.zf_height*.4];
//        _nameLab.textColor = [UIColor colorWithWhite:.2 alpha:1];
    }
    
    if (_timeLab.text.intValue == 0) {
        _timeLab.text = @"暂无视频";
        CGSize tSize = [@"暂无视频0" sizeWithFont:[UIFont systemFontOfSize:_timeLab.zf_height*.3] constrainedToSize:CGSizeMake(MAXFLOAT, 30)];
        _timeLab.frame = CGRectMake(self.zf_width-tSize.width, 0, tSize.width, self.zf_height);
    }else{
        _timeLab.frame = CGRectMake(self.zf_width-titleSize.width, 0, titleSize.width, self.zf_height);
    }
}

-(void)dealloc{
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _startP = [t locationInView:self];
    _gctimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(gctimerchange) userInfo:nil repeats:YES];
}

-(void)gctimerchange{
    _gc_num++;
}


-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _endP = [t locationInView:self];
    [self changemove];
}

-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _endP = [t locationInView:self];
    [self changemove];
}

-(void)changemove{
    [_gctimer invalidate];
    if (_gc_num>50) {
        _gc_num=0;
        if ([self.delegate respondsToSelector:@selector(clickWithTag:)]) {
            [self.delegate clickWithTag:self.tag];
        }
        return;
    }
    CGFloat x = _startP.x - _endP.x;
    
    CGFloat y = _startP.y - _endP.y;
    
    if (fabs(x)>fabs(y)) {
        if (fabs(x)>20) {
            if (x>0) {
                if ([self.delegate respondsToSelector:@selector(slidingDirection)]) {
                    [self.delegate slidingDirection];
                }
            }else{
                if ([self.delegate respondsToSelector:@selector(clickWithTag:)]) {
                    [self.delegate clickWithTag:self.tag];
                }
            }
        }else{
            if ([self.delegate respondsToSelector:@selector(clickWithTag:)]) {
                [self.delegate clickWithTag:self.tag];
            }
        }
    }else{
        if ([self.delegate respondsToSelector:@selector(clickWithTag:)]) {
            [self.delegate clickWithTag:self.tag];
        }
    }
}
- (NSString *)getVideoLengthFromTimeLength:(float)timeLength{
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:timeLength];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSInteger unitFlags = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ;
    NSDateComponents *components = [calendar components:unitFlags fromDate:date];

        return [NSString stringWithFormat:@"%zd:%@",components.minute,components.second < 10?[NSString stringWithFormat:@"0%zd",components.second]:[NSString stringWithFormat:@"%zd",components.second]];
}

@end

@protocol playlistViewDelegate <NSObject>

//-(void)ClickOnTheIndexPathRow:(NSInteger)row;

-(void)vslidingDirection;

@end

@interface gcplaylistView : UIView

@property(nonatomic,weak)id <playlistViewDelegate>delegate;

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *datas;

@property(nonatomic,assign)NSInteger selectNum;

@end

@interface gcplaylistView ()<UITableViewDataSource,UITableViewDelegate,OrderViewCellDelegate>

@end

@implementation gcplaylistView

-(void)slidingDirection{
    if ([self.delegate respondsToSelector:@selector(vslidingDirection)]) {
        [self.delegate vslidingDirection];
    }
}

-(void)setDatas:(NSMutableArray *)LabTitleStrs{
    _datas = LabTitleStrs;
    
    [_tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.datas.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return .0001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return .0001;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
    
}

-(void)clickWithTag:(NSInteger)tag{
    [[GCAVPlayer shared]playVideoIndex:tag];
    [_tableView reloadData];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    if ([self.delegate respondsToSelector:@selector(ClickOnTheIndexPathRow:)]) {
//        [self.delegate ClickOnTheIndexPathRow:indexPath.section];
//    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (HEIGHTDiv*.035+WIDTHDiv*.035);
}

static NSString *CellIdentifier = @"CELL";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    listCell *cell = [[listCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.tag = indexPath.section;
    cell.selectnum = _selectNum;
    cell.resDic = [NSDictionary setSafeDictionary:_datas[indexPath.section]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    return cell;
    
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _tableView.contentSize = CGSizeMake(WIDTHDiv, (HEIGHTDiv*.035+WIDTHDiv*.035)*(_datas.count+3));
}

-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    return _tableView;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _tableView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _datas = [NSMutableArray array];
        [self addSubview:self.tableView];
    }
    return self;
}

@end



@interface GCButton : UIButton

-(void)resume;
-(void)stop;
-(void)rotateView;

@end

@interface GCButton()

@property(nonatomic,assign)BOOL isRotating;

@end

@implementation GCButton

- (void)rotateView{
    CABasicAnimation *rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.removedOnCompletion = NO;
    rotationAnimation.toValue = [NSNumber numberWithFloat:M_PI*2.0];
    rotationAnimation.duration = 4;
    rotationAnimation.repeatCount = HUGE_VALF;
    rotationAnimation.speed = .5;
    [self.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
    self.isRotating = YES;
}

-(void)stop{
    self.isRotating = NO;
    CFTimeInterval pausedTime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
    self.layer.speed = 0;
    self.layer.timeOffset = pausedTime;
}
-(void)resume{
    if (self.isRotating) {
        return;
    }
    if (self.layer.timeOffset == 0) {
        [self rotateView];
        return;
    }
    self.isRotating = YES;
    CFTimeInterval pausedTime = self.layer.timeOffset;
    self.layer.speed = 1;
    self.layer.timeOffset = 0.01;
    self.layer.beginTime = 0.0;
    CFTimeInterval timeWhenpause = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
    self.layer.beginTime = timeWhenpause;
}

@end


@interface drawView : UIView

@property(nonatomic,assign)float progress;

@end

@implementation drawView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = NO;
        self.transform = CGAffineTransformMakeRotation(3*M_PI/2);
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
//    self.backgroundColor = [UIColor blueColor];
    UIColor *color = [UIColor colorWithRed:63/255.0 green:143/255.0 blue:247/255.0 alpha:1];
    [color set];
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2) radius:self.frame.size.height/2-3 startAngle:0 endAngle:(2*M_PI)*_progress clockwise:YES];
    path.lineWidth = 3.0;
    path.lineCapStyle = kCGLineCapRound;
    path.lineJoinStyle = kCGLineJoinRound;
    [path stroke];
}

@end


@protocol audioPlayerViewDelegate <NSObject>

@required

-(void)smallBtnClickWithTag:(NSInteger)tag;

-(void)bigBtnClickWithTag:(NSInteger)tag;

-(void)slierChange:(float)progress;

-(void)moveslier:(BOOL)ismoveslier;

@optional


@end


@interface audioPlayerView : UIView
@property(nonatomic,strong)NSDictionary *resDic;
@property (nonatomic ,weak) id <audioPlayerViewDelegate> delegate;
@property(nonatomic,assign)float progress;
@property(nonatomic,assign)float smallH;
@property(nonatomic,assign)BOOL iscollect;
@property(nonatomic,assign)NSInteger layoutType;
@property(nonatomic,weak)UIView *videoplayView;
@property(nonatomic,weak)UIView *svideoplayView;
@property(nonatomic,assign)NSInteger showType;  //什么类型视图  视频/音频/字幕
@property(nonatomic,weak)gcplaylistView *listV;

@property(nonatomic,strong)wordView *wordV;
-(void)backbtnClick;
-(void)viewisPlay:(BOOL)isplay;
-(void)updateProgress:(float)progress;
-(void)updatecacheProgress:(float)progress;
-(void)startLoading;
-(void)startPlay;
-(void)showLoginplayer;
@end

@interface audioPlayerView()<GCAVPlayerDelegate,JHPropressViewDelegate,playlistViewDelegate,wordViewDelegate,WKUIDelegate,WKNavigationDelegate>
@property(nonatomic,strong)UIView *smallView;
@property(nonatomic,strong)UIView *bigView;
@property(nonatomic,strong)drawView *dview;
@property(nonatomic,strong)GCButton *actView;
@property(nonatomic,strong)UIButton *resbtn;
@property(nonatomic,assign)BOOL isfirst;
@property(nonatomic,assign)BOOL ismoveslier;
@property(nonatomic,strong)JHPropressView *slider;
@property(nonatomic,assign)CGPoint startP;
@property(nonatomic,assign)CGPoint endP;
@property(nonatomic,assign)int gc_num;
@property(nonatomic,strong)NSTimer *gctimer;
@property(nonatomic,weak)UIView *conView;
@property(nonatomic,strong)UIView *audioMutView;
@property (nonatomic, strong) UITextView *contentTextView;
@end


@implementation audioPlayerView

-(UIView *)smallView{
    if (!_smallView) {
        _smallView = [UIView new];
        _smallView.backgroundColor = [UIColor colorWithHex:@"#F4F4F4"];
        _resbtn = [UIButton new];
        [_resbtn addTarget:self action:@selector(resbtnClick) forControlEvents:UIControlEventTouchUpInside];
        [_smallView addSubview:_resbtn];
        
        UIView *sview = [UIView new];
        sview.backgroundColor = [UIColor whiteColor];
        _svideoplayView = sview;
        _svideoplayView.hidden = YES;
        [_smallView addSubview:sview];
        
        for (int i  = 0; i < 3; i++) {
            GCButton *btn = [GCButton new];
            btn.tag = 100+i;
            [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            [_smallView addSubview:btn];
            UILabel *lab = [UILabel new];
            lab.tag = 200+i;
            if (i == 0) {
                lab.font = [UIFont systemFontOfSize:14];
                lab.textColor = [UIColor blackColor];
                lab.textAlignment = NSTextAlignmentLeft;
                btn.backgroundColor = [UIColor whiteColor];
            }
            
            if (i == 1) {
                
                [btn setImage:IMAGE(@"narrow_playBtn_play") forState:UIControlStateNormal];
                
                lab.textColor = [UIColor colorWithHex:@"#666666"];
            }
            if (i == 2) {
                [btn setImage:IMAGE(@"narrow_left_btn") forState:UIControlStateNormal];
                lab.textColor = [UIColor colorWithHex:@"#666666"];
            }
            [_smallView addSubview:lab];
        }
        _dview = [drawView new];
        [_smallView addSubview:_dview];
        _actView = [GCButton new];
        [_actView setImage:[UIImage imageNamed:@"Home_tab_loading"] forState:UIControlStateNormal];
        _actView.hidden = YES;
        [_smallView addSubview:_actView];
        
        
    }
    return _smallView;
}

-(void)btnClick:(UIButton *)sender{
    if (sender.tag-100 == 0) {
        if (_layoutType != 2) {
            _layoutType = 2;
            _resbtn.userInteractionEnabled = NO;
        }else if(_layoutType == 2){
            _resbtn.userInteractionEnabled = YES;
            _layoutType = 1;
        }
        [self setNeedsLayout];
    }else{
        if ([self.delegate respondsToSelector:@selector(smallBtnClickWithTag:)]) {
            [self.delegate smallBtnClickWithTag:sender.tag-100];
        }
    }
}

-(void)showLoginplayer{
    [self resbtnClick];
}

-(void)resbtnClick{
    _videoplayView.backgroundColor = [UIColor blackColor];
    _layoutType = 3;
    if ([GCAVPlayer shared].isAudio) {
        _showType = 1;
        _conView.zf_left = -WIDTHDiv;
    }else{
        _showType = 0;
        _conView.zf_left = 0;
        
        [_videoplayView.layer addSublayer:[GCAVPlayer shared].playerLayer];
        [GCAVPlayer shared].playerLayer.frame = CGRectMake(0, 0, WIDTHDiv, WIDTHDiv*9/16.0);
    }
    [self setNeedsLayout];
}

- (void)returnPress:(float)sliderValue andIscache:(BOOL)isCache{
    if ([self.delegate respondsToSelector:@selector(slierChange:)]) {
        [self.delegate slierChange:sliderValue];
    }
    _audioMutView.hidden = NO;
    for (int i = 0 ; i < 3; i++) {
        UILabel *lab = [_conView viewWithTag:520+i];
        if (i == 0) {
            lab.hidden = NO;
        }else if (i == 1){
            lab.hidden = YES;
        }else{
            lab.hidden = NO;
        }
    }
}

-(void)wslierChange:(float)progress{
    if ([self.delegate respondsToSelector:@selector(slierChange:)]) {
        [self.delegate slierChange:progress];
    }
}

-(void)wmoveslier:(BOOL)ismoveslier{
    if ([self.delegate respondsToSelector:@selector(moveslier:)]) {
        [self.delegate moveslier:ismoveslier];
    }
}

- (void)returnMove:(float)sliderValue{
    UILabel *lab = [_conView viewWithTag:521];
    
    lab.text = [NSString stringWithFormat:@"%@/%@",[toolHelp timeFormatted:sliderValue*[GCAVPlayer shared].videoLength],[toolHelp timeFormatted:(int)[GCAVPlayer shared].videoLength]];
}

- (void)returnBegan:(BOOL)isMove andIscache:(BOOL)isCache{
    _ismoveslier = isMove;
//    if (_ismoveslier) {
        
        if ([self.delegate respondsToSelector:@selector(moveslier:)]) {
            [self.delegate moveslier:isMove];
        }
//    }
    _audioMutView.hidden = YES;
    for (int i = 0 ; i < 3; i++) {
        UILabel *lab = [_conView viewWithTag:520+i];
        if (i == 0) {
            lab.hidden = YES;
        }else if (i == 1){
            lab.hidden = NO;
        }else{
            lab.hidden = YES;
        }
    }
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _startP = [t locationInView:self];
    _gctimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(gctimerchange) userInfo:nil repeats:YES];
    
}

-(void)gctimerchange{
    _gc_num++;
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _endP = [t locationInView:self];
    [self changemove];
    
}

-(void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *t = [touches anyObject];
    _endP = [t locationInView:self];
    [self changemove];
    
}

-(void)vslidingDirection{
    _showType++;
    UIButton *btn_type = [_bigView viewWithTag:501+_showType];
    UIView *typeBg = [_bigView viewWithTag:500];
    typeBg.frame = CGRectMake(btn_type.zf_left+btn_type.zf_width*.3, btn_type.zf_bottom*1.04, btn_type.zf_width*.4, 0.01*WIDTHDiv);
    UIView *contentView = [_bigView viewWithTag:666];
    [UIView animateWithDuration:.25 animations:^{
        contentView.zf_left -= WIDTHDiv;
        UIImageView *bgImg1 = [self->_bigView viewWithTag:10087];
        if (self->_showType == 0) {
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.65];
        }else if (self->_showType == 1){
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.15];
        }else{
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.35];
        }
    }];
    for (int i = 0; i < 3; i++) {
        UIButton *lab = [_bigView viewWithTag:501+i];
        if (i == _showType) {
            [lab setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.75];
        }else{
            [lab setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
            lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.65];
        }
    }
}

-(void)wslidingDirection{
    _showType--;
    UIButton *btn_type = [_bigView viewWithTag:501+_showType];
    UIView *typeBg = [_bigView viewWithTag:500];
    typeBg.frame = CGRectMake(btn_type.zf_left+btn_type.zf_width*.3, btn_type.zf_bottom*1.04, btn_type.zf_width*.4, 0.01*WIDTHDiv);
    UIView *contentView = [_bigView viewWithTag:666];
    [UIView animateWithDuration:.25 animations:^{
        contentView.zf_left += WIDTHDiv;
        UIImageView *bgImg1 = [self->_bigView viewWithTag:10087];
        if (self->_showType == 0) {
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.65];
        }else if (self->_showType == 1){
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.15];
        }else{
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.35];
        }
    }];
    for (int i = 0; i < 3; i++) {
        UIButton *lab = [_bigView viewWithTag:501+i];
        if (i == _showType) {
            [lab setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.75];
        }else{
            [lab setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
            lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.65];
        }
    }
}

-(void)changemove{
    [_gctimer invalidate];
    if (_gc_num>50) {
        _gc_num=0;
        return;
    }
    CGFloat x = _startP.x - _endP.x;

    CGFloat y = _startP.y - _endP.y;

    if (fabs(x)>fabs(y)) {
//        if (fabs(x)>20) {
//            if (x>0) {
//                if(_showType==2){
//                    return;
//                }
//                _showType++;
//                UIButton *btn_type = [_bigView viewWithTag:501+_showType];
//                UIView *typeBg = [_bigView viewWithTag:500];
//                typeBg.frame = CGRectMake(btn_type.zf_left+btn_type.zf_width*.3, btn_type.zf_bottom*1.04, btn_type.zf_width*.4, 0.01*WIDTHDiv);
//                UIView *contentView = [_bigView viewWithTag:666];
//                [UIView animateWithDuration:.25 animations:^{
//                    contentView.zf_left -= WIDTHDiv;
//
//                }];
//                for (int i = 0; i < 3; i++) {
//                    UIButton *lab = [_bigView viewWithTag:501+i];
//                    if (i == _showType) {
//                        [lab setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//                        lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.75];
//                    }else{
//                        [lab setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
//                        lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.65];
//                    }
//                }
//            }else{
//                if(_showType==0){
//                    return;
//                }
//                _showType--;
//                UIButton *btn_type = [_bigView viewWithTag:501+_showType];
//                UIView *typeBg = [_bigView viewWithTag:500];
//                typeBg.frame = CGRectMake(btn_type.zf_left+btn_type.zf_width*.3, btn_type.zf_bottom*1.04, btn_type.zf_width*.4, 0.01*WIDTHDiv);
//                UIView *contentView = [_bigView viewWithTag:666];
//                [UIView animateWithDuration:.25 animations:^{
//                    contentView.zf_left += WIDTHDiv;
//                }];
//                for (int i = 0; i < 3; i++) {
//                    UIButton *lab = [_bigView viewWithTag:501+i];
//                    if (i == _showType) {
//                        [lab setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//                        lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.75];
//                    }else{
//                        [lab setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
//                        lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.65];
//                    }
//                }
//            }
//        }
    }else{
        if (fabs(y)>20) {
            if (y<0) {
                _layoutType = 1;
                UIImageView *bgImg1 = [_bigView viewWithTag:10087];
                if (![GCAVPlayer shared].isAudio) {
                    bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.65];
                    _videoplayView.backgroundColor = [UIColor clearColor];
                    [_svideoplayView.layer addSublayer:[GCAVPlayer shared].playerLayer];
                }else{
                    bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.15];
                }
                [self setNeedsLayout];
            }
        }
    }
}

-(void)initAudioUI{
    UIImageView *bgImg = [UIImageView new];
    bgImg.image = [UIImage imageNamed:@"playerBg"];
    bgImg.tag = 10086;
    bgImg.userInteractionEnabled = true;
    [_bigView addSubview:bgImg];
    UIImageView *bgImg1 = [UIImageView new];
    bgImg1.tag = 10087;
    bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.15];
    [_bigView addSubview:bgImg1];
    
    UIView *contentView = [UIView new];
    contentView.tag = 666;
//            contentView.layer.zPosition = -10;
    [_bigView addSubview:contentView];
    _conView = contentView;
    
    UIButton *backbtn = [UIButton new];
    [backbtn setImage:[UIImage imageNamed:@"icon_fanhui"] forState:UIControlStateNormal];
    backbtn.tag = 1050;
    [backbtn addTarget:self action:@selector(backbtnClick) forControlEvents:UIControlEventTouchUpInside];
    [_bigView addSubview:backbtn];
    
    UILabel *classLab = [UILabel new];
    classLab.tag = 101;
//            classLab.text= @"二级分类";
    classLab.textColor = [UIColor whiteColor];
    [_bigView addSubview:classLab];
    
    UILabel *class1Lab = [UILabel new];
    class1Lab.tag = 102;
//            class1Lab.text= @"一级分类";
    class1Lab.textColor = [UIColor colorWithWhite:1 alpha:0.5];
    [_bigView addSubview:class1Lab];
    
    NSArray *typeArr = @[@"视频",@"音频",@"字幕"];
    for (int i=0 ; i<3; i++) {
        UIButton *btn_type = [UIButton new];
        btn_type.tag = 501+i;
        btn_type.titleLabel.textAlignment = NSTextAlignmentCenter;
//                btn_type.backgroundColor = [UIColor redColor];
        [btn_type setTitle:typeArr[i] forState:UIControlStateNormal];
        [btn_type addTarget:self action:@selector(btn_type:) forControlEvents:UIControlEventTouchUpInside];
        [_bigView addSubview:btn_type];
    }
    
    UIView *typeBg = [UIView new];
    typeBg.tag = 500;
    typeBg.backgroundColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
    [_bigView addSubview:typeBg];
    
    
    
    //背景
//    for (int i = 0; i < 3; i++) {
//        UIView *blackView = [UIView new];
//        blackView.tag = 90+i;
//        if (i == 0) {
//            blackView.backgroundColor = [UIColor colorWithWhite:0 alpha:.75];
//        }else if (i == 1){
//            blackView.backgroundColor = [UIColor colorWithWhite:0 alpha:.25];
//        }else if (i == 2){
//            blackView.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
//        }
//        [contentView addSubview:blackView];
//    }
    
    //标题
    for (int i = 0; i < 2; i++) {
        UILabel *classLab = [UILabel new];
        if (i == 0) {
            classLab.backgroundColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
        }
        classLab.textColor = [UIColor whiteColor];
        classLab.tag = 200+i;
        [contentView addSubview:classLab];
    }
    
    //底部四个功能键
    NSArray *functionArr = @[@"循环播放",@"倍速1.0",@"定时器关闭",@"目录"];
    for (int i=0 ; i<4; i++) {
        UIButton *btn_function = [UIButton new];
//        btn_function.backgroundColor = [UIColor greenColor];
        [btn_function setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",functionArr[i]]] forState:UIControlStateNormal];
            btn_function.tag = 800+i;
//            btn_function.backgroundColor = [UIColor redColor];
            [btn_function addTarget:self action:@selector(btn_function:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:btn_function];
        if (i == 1) {
            if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"playbeishu"] floatValue] == 0) {
                [[NSUserDefaults standardUserDefaults] setValue:@"1.0" forKey:@"playbeishu"];
                [[NSUserDefaults standardUserDefaults] synchronize];
            }
//            NSLog(@"1112~~~>>%@",[NSString stringWithFormat:@"%.1lf",[[[NSUserDefaults standardUserDefaults] valueForKey:@"playbeishu"] floatValue]]);
            [btn_function setImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@",[NSString stringWithFormat:@"%.1lf",[[[NSUserDefaults standardUserDefaults] valueForKey:@"playbeishu"] floatValue]]]] forState:UIControlStateNormal];
        }
        if (i == 0) {
            NSArray *asss = @[@"循环播放",@"单曲播放",@"随机播放"];
            NSInteger subtag = [[NSUserDefaults standardUserDefaults] integerForKey:@"gcplaytype"];
            [btn_function setImage:[UIImage imageNamed:asss[subtag]] forState:UIControlStateNormal];
        }
    }
    
    //播放功能键
    NSArray *playArr = @[@"icon_上一首",@"icon_playImg",@"icon_下一首"];
    for (int i=0 ; i<3; i++) {
    UIButton *btn_play = [UIButton new];
    [btn_play setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",playArr[i]]] forState:UIControlStateNormal];
        btn_play.tag = 800+i+4;
//            btn_play.backgroundColor = [UIColor redColor];
        [btn_play addTarget:self action:@selector(btn_function:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:btn_play];
    }
    
    
    
    //前进、后退10秒
    NSArray *skipArr = @[@"后退10秒",@"前进10秒"];
    for (int i=0 ; i<2; i++) {
        UIButton *btn_skip = [UIButton new];
        btn_skip.tag = 800 + i+7;
        [btn_skip setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",skipArr[i]]] forState:UIControlStateNormal];
        [btn_skip addTarget:self action:@selector(btn_function:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:btn_skip];
    }
    
    _slider = [JHPropressView new];
    _slider.delegate = self;
    _slider.isCache = YES;
    _slider.jhImage = [UIImage imageNamed:@"gc_slider"];
//            _slider.pressView.backgroundColor = [UIColor colorWithRed:246/255.0 green:191/255.0 blue:66/255.0 alpha:1];
    [contentView addSubview:_slider];
    
    
    for (int i = 0 ; i < 3; i++) {
        UILabel *lab = [UILabel new];
        lab.textColor = [UIColor colorWithWhite:.95 alpha:1];
//            lab.backgroundColor = [UIColor greenColor];
        lab.tag = 520+i;
        if (i == 0) {
            lab.textAlignment = NSTextAlignmentLeft;
        }else if (i == 1){
            lab.textAlignment = NSTextAlignmentCenter;
            lab.hidden = YES;
        }else{
            lab.textAlignment = NSTextAlignmentRight;
        }
        [contentView addSubview:lab];
    }
    
    NSArray *righttopArr = @[@"icon_Collect_default",@""];
    for (int i=0 ; i<2; i++) {
    UIButton *rtopBtn = [UIButton new];
        [rtopBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",righttopArr[i]]] forState:UIControlStateNormal];
        rtopBtn.tag = 800+i+9;
        if (i == 1) {
            rtopBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
            UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_wenjian"]];
            img.tag = 770;
            [rtopBtn addSubview:img];
            UILabel *rtlab = [UILabel new];
            rtlab.tag = 780;
            rtlab.textColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
            rtlab.textAlignment = NSTextAlignmentCenter;
            rtlab.text = @"文件";
            [rtopBtn addSubview:rtlab];
        }
        [rtopBtn addTarget:self action:@selector(rtopBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_bigView addSubview:rtopBtn];
    }
    
    _audioMutView = [UIView new];
//    _audioMutView.backgroundColor = [UIColor colorWithRed:.25 green:0 blue:0 alpha:.25];
    [_conView addSubview:_audioMutView];
    
    for (int i = 0; i < 3; i++) {
        UIView *contextV = [UIView new];
        contextV.tag = 680+i;
//        contextV.backgroundColor = [UIColor colorWithRed:i == 0?.8:.2 green:i == 0?.3:.6 blue:i == 2?.5:0 alpha:.25];
        [_audioMutView addSubview:contextV];
    }
    
}

-(void)setIscollect:(BOOL)iscollect{
    _iscollect = iscollect;
    UIButton *rtopBtn = [_bigView viewWithTag:809];
    [rtopBtn setImage:_iscollect?[UIImage imageNamed:@"icon_Collect_select"]:[UIImage imageNamed:@"icon_Collect_default"] forState:UIControlStateNormal];
}

-(void)rtopBtnClick:(UIButton *)sender{
    NSLog(@"~~~>>%zd",sender.tag - 809);
    
    if ([self.delegate respondsToSelector:@selector(bigBtnClickWithTag:)]) {
        [self.delegate bigBtnClickWithTag:sender.tag-800];
    }
}

-(UIView *)bigView{
    if (!_bigView) {
        _bigView = [UIView new];
        _bigView.backgroundColor = [UIColor yellowColor];
        
        
        //音频
        [self initAudioUI];
        
        //视频
        {
            UIView *playerView = [UIView new];
            _videoplayView = playerView;
            _videoplayView.backgroundColor = [UIColor blackColor];
            playerView.tag = 1999;
            [_conView addSubview:playerView];
            
            for (int i = 0; i < 2; i++) {
                UILabel *classLab = [UILabel new];
                classLab.tag = 1000+i;
                
                [_conView addSubview:classLab];
                
                UIImageView *img = [UIImageView new];
                img.tag = 2000+i;
                [_conView addSubview:img];
                
                if (i == 0) {
                    classLab.textColor = [UIColor whiteColor];
                    img.backgroundColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
                }else{
                    classLab.textColor = [UIColor colorWithWhite:.75 alpha:1];
                    classLab.numberOfLines = 0;
                    img.image = [UIImage imageNamed:@"liebiao"];
                }
            }
            UIButton *btn = [UIButton new];
            btn.tag = 3000;
            [btn setImage:[UIImage imageNamed:@"循环播放"] forState:UIControlStateNormal];
            [_conView addSubview:btn];
            
            gcplaylistView *listView = [gcplaylistView new];
            listView.delegate = self;
            [_conView addSubview:listView];
            _listV = listView;
            
        }
        
        //字幕
        {
            //标题
            for (int i = 0; i < 2; i++) {
                UILabel *classLab = [UILabel new];
                classLab.tag = 300+i;
                classLab.textColor = [UIColor whiteColor];
                if (i == 0) {
                    classLab.backgroundColor = [UIColor colorWithRed:65/255.0 green:134/255.0 blue:233/255.0 alpha:1];
                }
                [_conView addSubview:classLab];
            }
            
            _wordV = [wordView new];
            _wordV.delegate = self;
            [_conView addSubview:_wordV];
        }
        
        
    }
    return _bigView;
}

-(void)beishuclick:(NSString *)str{
    UIButton *btn = [_conView viewWithTag:801];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@", str]] forState:UIControlStateNormal];
}

-(void)btn_function:(UIButton *)sender{
    if (sender.tag - 800 == 1) {
        PlayMulitplePopView *view = [[PlayMulitplePopView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        view.mulitBlock = ^(NSString * _Nonnull mulit) {
            [GCAVPlayer shared].player.rate = mulit.floatValue;
            [sender setImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@", mulit]] forState:UIControlStateNormal];
            [[NSUserDefaults standardUserDefaults] setValue:mulit forKey:@"playbeishu"];
            [[NSUserDefaults standardUserDefaults] synchronize];
            
            UIButton *btn = [self.wordV.playconView viewWithTag:60];
            [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"倍速%@", mulit]] forState:UIControlStateNormal];
        };
        
        [view showIn:[[[UIApplication sharedApplication] delegate] window] currentMulitple:[NSString stringWithFormat:@"%f",[GCAVPlayer shared].player.rate]];
    }else if (sender.tag - 800 == 0){
        NSArray *asss = @[@"循环播放",@"单曲播放",@"随机播放"];
        NSInteger subtag = [[NSUserDefaults standardUserDefaults] integerForKey:@"gcplaytype"];
        subtag++;
        if (subtag == 3) {
            subtag = 0;
        }
        [sender setImage:[UIImage imageNamed:asss[subtag]] forState:UIControlStateNormal];
        [[NSUserDefaults standardUserDefaults] setInteger:subtag forKey:@"gcplaytype"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [GCAVPlayer shared].playStyle = subtag;
    }
//    else if (sender.tag - 800 == 2){
//        PlayListView *listView  = [[PlayListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//
//        UIView *superView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
//        if (!superView) {
//            superView = [UIApplication sharedApplication].keyWindow;
//        }
//
//        [listView showIn:[[[UIApplication sharedApplication] delegate] window] listArray:_playlistDatas IdStr:_playlistDatas[_index][@"id"]];
//
//        NSArray *titleArray = [[NSString setSafeString:_resDic[@"media_class_name"]] componentsSeparatedByString:@"|"];
//        if (titleArray.count >= 2) {
//
//            listView.subTitleStr = titleArray[1];
//        }
//    }
    else{
        if ([self.delegate respondsToSelector:@selector(bigBtnClickWithTag:)]) {
            [self.delegate bigBtnClickWithTag:sender.tag-800];
        }
    }
}

#pragma mark 点击切换类型
-(void)btn_type:(UIButton*)sender{//501+i
    _showType = sender.tag-501;
    UIView *typeBg = [_bigView viewWithTag:500];
    typeBg.frame = CGRectMake(sender.zf_left+sender.zf_width*.3, sender.zf_bottom*1.04, sender.zf_width*.4, 0.01*WIDTHDiv);
    UIView *contentView = [_bigView viewWithTag:666];
    UIImageView *bgImg1 = [_bigView viewWithTag:10087];
    
    [UIView animateWithDuration:.25 animations:^{
        contentView.zf_left = -(self->_showType)*WIDTHDiv;
        if (self->_showType == 0) {
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.65];
        }else if (self->_showType == 1){
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.15];
        }else{
            bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.35];
        }
    }];
    
    for (int i = 0; i < 3; i++) {
        UIButton *lab = [_bigView viewWithTag:501+i];
        if ([lab isKindOfClass:[UIButton class]]) {
            if (i == _showType) {
                [lab setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.75];
            }else{
                [lab setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
                lab.titleLabel.font = [UIFont boldSystemFontOfSize:lab.zf_height*0.65];
            }
        }
    }
    
}

-(void)backbtnClick{
    _layoutType = 1;
    UIImageView *bgImg1 = [_bigView viewWithTag:10087];
    if (![GCAVPlayer shared].isAudio) {
        bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.65];
        _videoplayView.backgroundColor = [UIColor clearColor];
        [_svideoplayView.layer addSublayer:[GCAVPlayer shared].playerLayer];
    }else{
        bgImg1.backgroundColor = [UIColor colorWithWhite:0 alpha:.15];
    }
    [self setNeedsLayout];
}

-(void)viewisPlay:(BOOL)isplay{
    GCButton *btn = [_smallView viewWithTag:100];
    GCButton *btn1 = [_smallView viewWithTag:101];
    UIButton *btn_play = [_conView viewWithTag:805];
    if (isplay) {
        [btn resume];
        [btn1 setImage:IMAGE(@"narrow_playBtn_play") forState:UIControlStateNormal];
        
        [btn_play setImage:IMAGE(@"icon_stopImg") forState:UIControlStateNormal];
        [_wordV.playBtn setImage:[UIImage imageNamed:@"narrow_playBtn_play"] forState:UIControlStateNormal];
    }else{
        [btn stop];
        [btn1 setImage:IMAGE(@"narrow_playBtn_puse") forState:UIControlStateNormal];
        [btn_play setImage:IMAGE(@"icon_playImg") forState:UIControlStateNormal];
        [_wordV.playBtn setImage:[UIImage imageNamed:@"narrow_playBtn_puse"] forState:UIControlStateNormal];
    }
}

-(void)updateProgress:(float)progress{
//    NSLog(@"updateProgress~~~>%lf",progress);
    _dview.progress = progress/[GCAVPlayer shared].videoLength;
    _slider.press = progress/[GCAVPlayer shared].videoLength;
    int aaa = [[NSString setSafeString:_resDic[@"audio_num"]] intValue];
    if (![GCAVPlayer shared].isAudio) {
        aaa = [[NSString setSafeString:_resDic[@"video_num"]] intValue];
    }
    for (int i = 0; i < 3; i++) {
        UILabel *lab = [_conView viewWithTag:520+i];
        if (i == 0) {
            lab.text = [toolHelp timeFormatted:progress];
        }else if (i == 1){
            lab.text = [NSString stringWithFormat:@"%@/%@",[toolHelp timeFormatted:(int)progress],[toolHelp timeFormatted:aaa]];
        }else{
            lab.text = [toolHelp timeFormatted:aaa];
        }
    }
    
    [_dview setNeedsDisplay];
}

-(void)updatecacheProgress:(float)progress{
    _slider.cachepress = progress;
}

-(void)setResDic:(NSDictionary *)resDic{
    _resDic = resDic;
    NSLog(@"setResDic~~~>>%@",_resDic);
    
    
    float progress = 0;
    int aaa = [[NSString setSafeString:_resDic[@"audio_num"]] intValue];
    if (![GCAVPlayer shared].isAudio) {
        aaa = [[NSString setSafeString:_resDic[@"video_num"]] intValue];
    }
    for (int i = 0; i < 3; i++) {
        UILabel *lab = [_conView viewWithTag:520+i];
        if (i == 0) {
            lab.text = [toolHelp timeFormatted:progress];
        }else if (i == 1){
            lab.text = [NSString stringWithFormat:@"%@/%@",[toolHelp timeFormatted:(int)progress],[toolHelp timeFormatted:aaa]];
        }else{
            lab.text = [toolHelp timeFormatted:aaa];
        }
    }
    _slider.press = 0;
    _slider.cachepress = 0;
    
    GCButton *btn = [_smallView viewWithTag:100];
    [btn sd_setImageWithURL:[NSURL URLWithString:[NSString setSafeString:resDic[@"image"]]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"default"]];
    UILabel *lab = [_smallView viewWithTag:200];
    lab.text = [NSString setSafeString:resDic[@"name"]];
    UILabel *lab1 = [_smallView viewWithTag:201];
    lab1.text = [NSString setSafeString:resDic[@"media_class_name"]];
    
    UILabel *classLab = [_bigView viewWithTag:101];
    classLab.text = [[[NSString setSafeString:_resDic[@"media_class_name"]] componentsSeparatedByString:@"|"] firstObject];
    UILabel *classLab1 = [_bigView viewWithTag:102];
    classLab1.text = [[[NSString setSafeString:_resDic[@"media_class_name"]] componentsSeparatedByString:@"|"] lastObject];
    UILabel *clab = [_conView viewWithTag:1000];
    clab.text = [NSString setSafeString:_resDic[@"name"]];
    UILabel *clab1 = [_conView viewWithTag:1001];
    clab1.text = [NSString setSafeString:_resDic[@"describe"]];
    
    UILabel *classLabaaa = [_conView viewWithTag:201];
    classLabaaa.text = [NSString setSafeString:resDic[@"name"]];
    UILabel *classLabbbb = [_conView viewWithTag:301];
    classLabbbb.text = [NSString setSafeString:resDic[@"name"]];
    
    NSArray *additionals = _resDic[@"additional"];
    NSArray *lables = _resDic[@"lable"];
    NSString *introduce = [NSString setSafeString:_resDic[@"introduce"]];
    for (int i = 0; i < 3; i++) {
        UIView *contextV = [_audioMutView viewWithTag:680+i];
        for (int j = 0; j < contextV.subviews.count; j++) {
            UIView *aaa = contextV.subviews[j];
            [aaa removeFromSuperview];
        }
        if (i == 0) {
            if (introduce.length != 0) {
                NSLog(@"introduceintroduceintroduce~~>>%@",introduce);
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:[introduce dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];
                    [attrStr enumerateAttribute:NSFontAttributeName
                                                 inRange:NSMakeRange(0, attrStr.string.length)
                                                 options:(NSAttributedStringEnumerationReverse) usingBlock:^(UIFont *value, NSRange range, BOOL * _Nonnull stop){
                                                     if (value) {
                                                         *stop = YES;
                                                         [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:LYRICSH*.35] range:range];

                                                     }else{
                                                         [attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:LYRICSH*.35] range:range];
                                                     }
                    }];
                    
                    NSLog(@"~~~~~~~~~~~~~~~~~~NSMutableAttributedString~~~~~~~~~~");
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (!self->_contentTextView.superview) {
                            self->_contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, WIDTHDiv, HEIGHTDiv)];
                            self->_contentTextView.editable = NO;
                            
                            self->_contentTextView.backgroundColor = [UIColor clearColor];
                            [contextV addSubview:self->_contentTextView];
                        }
                        self->_contentTextView.attributedText = attrStr;
                    });
                });
                
            }
        }else if (i == 1){
            if (additionals.count != 0) {
                UILabel *additionalLab = [UILabel new];
                additionalLab.tag = 639;
                additionalLab.text = @"附件:";
                additionalLab.textColor = [UIColor whiteColor];
                [contextV addSubview:additionalLab];
                
                for (int i = 0; i < additionals.count; i++) {
                    if (i < 6) {
                        NSDictionary *dic = additionals[i];
                        UIButton *additionalbtn = [UIButton new];
                        additionalbtn.tag = 630+i;
                        [additionalbtn setTitle:[NSString setSafeString:dic[@"title"]] forState:UIControlStateNormal];
                        [additionalbtn addTarget:self action:@selector(additionalbtnClick:) forControlEvents:UIControlEventTouchUpInside];
                        [contextV addSubview:additionalbtn];
                    }
                }
                
            }
        }else{
            if (lables.count != 0) {
                UILabel *labLab = [UILabel new];
                labLab.tag = 649;
                labLab.text = @"相关:";
                labLab.textColor = [UIColor whiteColor];
                [contextV addSubview:labLab];
                
                for (int i = 0; i < lables.count; i++) {
                    if (i < 6) {
                        NSDictionary *dic = lables[i];
                        UIButton *labbtn = [UIButton new];
                        labbtn.tag = 640+i;
                        [labbtn setTitle:[NSString setSafeString:dic[@"label"]] forState:UIControlStateNormal];
                        [labbtn addTarget:self action:@selector(labbtnClick:) forControlEvents:UIControlEventTouchUpInside];
                        [contextV addSubview:labbtn];
                    }
                }
                
            }
        }
    }
    
    [self setNeedsLayout];
    
}

- (NSString *)removeSpaceAndNewline:(NSString *)str{
    NSString *temp = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    return temp;
}


-(void)labbtnClick:(UIButton *)sender{
    NSLog(@"~~~~>>%zd",sender.tag - 640);
}

-(void)additionalbtnClick:(UIButton *)sender{
    NSLog(@"~~~~>>%zd",sender.tag - 630);
}

-(void)startLoading{
    _actView.hidden = NO;
    [_actView resume];
    GCButton *btn1 = [_smallView viewWithTag:101];
    btn1.hidden = YES;
    _dview.hidden = YES;
    _dview.progress = 0;
    [_dview setNeedsDisplay];
}

-(void)startPlay{
    [_wordV updateLry];
    _actView.hidden = YES;
    [_actView stop];
    GCButton *btn1 = [_smallView viewWithTag:101];
    btn1.hidden = NO;
    _dview.hidden = NO;
}

-(void)setSmallH:(float)smallH{
    _smallH = smallH;
    [self setNeedsLayout];
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self addSubview:self.smallView];
        [self addSubview:self.bigView];
        _isfirst = YES;
//        _showType = 1;
        _layoutType = 1;
    }
    return self;
}

-(void)setLayoutType:(NSInteger)type{
    _layoutType = type;
    [self setNeedsLayout];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    UIButton *backbtn = [_bigView viewWithTag:1050];
    if (_isfirst) {
        _isfirst = NO;
//        if (_type == 1) {
            [self refreshType1];
//        }
        _bigView.frame = CGRectMake(0, HEIGHTDiv, WIDTHDiv, HEIGHTDiv);
        UIImageView *bgImg = [_bigView viewWithTag:10086];
        bgImg.frame = CGRectMake(0, (HEIGHTDiv-WIDTHDiv/.462)/2, WIDTHDiv, WIDTHDiv/.462);
        UIImageView *bgImg1 = [_bigView viewWithTag:10087];
        bgImg1.frame = CGRectMake(0, (HEIGHTDiv-WIDTHDiv/.462)/2, WIDTHDiv, WIDTHDiv/.462);
                
        //返回按钮
        
        backbtn.frame = CGRectMake(0, 0.05*HEIGHTDiv, 0.08*WIDTHDiv, 0.08*WIDTHDiv);
       
        
        //二级分类lab
        UILabel *classLab = [_bigView viewWithTag:101];
        classLab.frame = CGRectMake(backbtn.zf_right, backbtn.zf_top, 0.6*WIDTHDiv, 0.028*HEIGHTDiv);
        classLab.font = [UIFont boldSystemFontOfSize:classLab.zf_height*.75];

        //一级分类lab
        UILabel *class1Lab = [_bigView viewWithTag:102];
        class1Lab.frame = CGRectMake(backbtn.zf_right, classLab.zf_bottom, 0.6*WIDTHDiv, 0.015*HEIGHTDiv);
        class1Lab.font = [UIFont systemFontOfSize:class1Lab.zf_height*.8];
        
        
        
        //可滑动view
        UIView *contentView = [_bigView viewWithTag:666];
        contentView.frame = CGRectMake(-_showType*WIDTHDiv, 0.15*HEIGHTDiv, 3*WIDTHDiv, 0.83*HEIGHTDiv);
        
        {
//            for (int i = 0; i < 3; i++) {
//                UIView *blackView = [contentView viewWithTag:90+i];
//                if (i == 0) {
//                    blackView.frame = CGRectMake(i*WIDTHDiv, 0.15*HEIGHTDiv, WIDTHDiv, HEIGHTDiv);
//                }else if (i == 1){
//                    blackView.frame = CGRectMake(-_showType*WIDTHDiv, 0.15*HEIGHTDiv, 3*WIDTHDiv, 0.83*HEIGHTDiv);
//                }else if (i == 2){
//                    blackView.frame = CGRectMake(-_showType*WIDTHDiv, 0.15*HEIGHTDiv, 3*WIDTHDiv, 0.83*HEIGHTDiv);
//                }
//                blackView.frame = CGRectMake(i*WIDTHDiv, -0.15*HEIGHTDiv, WIDTHDiv, HEIGHTDiv);
//            }
            
            for (int i = 0; i < 2; i++) {
                UILabel *classLab = [_conView viewWithTag:200+i];
                if (i == 0) {
                    classLab.frame = CGRectMake(WIDTHDiv+0.02*WIDTHDiv, .04*WIDTHDiv, .01*WIDTHDiv, .04*WIDTHDiv);
                }else{
                    classLab.frame = CGRectMake(WIDTHDiv+0.05*WIDTHDiv, 0.02*WIDTHDiv, WIDTHDiv -0.07*WIDTHDiv , .08*WIDTHDiv);
                    classLab.font = [UIFont boldSystemFontOfSize:classLab.zf_height*.55];
                }
            }
            
            // -------------------------------
             //底部四个功能键
             for (int i=0 ; i<4; i++) {
                 float w = 0.03*WIDTHDiv+.025*HEIGHTDiv;
                 float jx = (WIDTHDiv - w*4)/5;
                 UIButton *btn_function = [contentView viewWithTag:800+i];
//                 btn_function.backgroundColor = [UIColor redColor];
                 btn_function.frame = CGRectMake(WIDTHDiv+jx+i%4*(w+jx), 0.75*HEIGHTDiv, w, w);

                 
             }
             
             //播放功能键
             for (int i=0 ; i<3; i++) {
             UIButton *btn_play = [contentView viewWithTag:800+i+4];
                 btn_play.frame = CGRectMake(1.2*WIDTHDiv+ i%3*0.25*WIDTHDiv, 0.66*HEIGHTDiv, 0.08*WIDTHDiv, 0.08*WIDTHDiv);
                 if(i== 1){//   播放按钮
                   
                     btn_play.frame = CGRectMake(1.4*WIDTHDiv, 0.66*HEIGHTDiv-0.06*WIDTHDiv, 0.2*WIDTHDiv, 0.2*WIDTHDiv);
                     btn_play.layer.cornerRadius = btn_play.zf_width/2;
                     btn_play.layer.masksToBounds = YES;
                     btn_play.backgroundColor = [UIColor colorWithWhite:.8 alpha:.3];
                 }
             }
             //跳过10秒
             for (int i=0 ; i<2; i++) {
                 UIButton *btn_skip = [contentView viewWithTag:800+i+7];
                 btn_skip.frame = CGRectMake(1.05*WIDTHDiv + i%2*0.8*WIDTHDiv, 0.55*HEIGHTDiv, 0.03*WIDTHDiv+.03*HEIGHTDiv, 0.03*WIDTHDiv+.03*HEIGHTDiv);
             }

             _slider.frame = CGRectMake(1.1*WIDTHDiv+0.03*WIDTHDiv+.03*HEIGHTDiv, 0.55*HEIGHTDiv+.015*HEIGHTDiv, WIDTHDiv-(0.03*WIDTHDiv+.03*HEIGHTDiv)*2-.2*WIDTHDiv, 0.03*WIDTHDiv);
             _slider.lineWith = 0.02*WIDTHDiv;
            
            for (int i = 0 ; i < 3; i++) {
                UILabel *lab = [_conView viewWithTag:520+i];
                if (i == 0) {
                    lab.frame = CGRectMake(_slider.zf_left, _slider.zf_bottom+WIDTHDiv*.01, _slider.zf_width/2, 0.05*WIDTHDiv);
                    lab.font = [UIFont systemFontOfSize:.04*WIDTHDiv];
                }else if (i == 1){
                    lab.frame = CGRectMake(_slider.zf_left, _slider.zf_top-0.1*WIDTHDiv, _slider.zf_width, 0.08*WIDTHDiv);
                    lab.font = [UIFont systemFontOfSize:.05*WIDTHDiv];
                    _audioMutView.frame = CGRectMake(WIDTHDiv, .1*WIDTHDiv, WIDTHDiv,  lab.zf_top - .1*WIDTHDiv);
                }else{
                    lab.frame = CGRectMake(_slider.zf_left+_slider.zf_width/2, _slider.zf_bottom+WIDTHDiv*.01, _slider.zf_width/2, 0.05*WIDTHDiv);
                    lab.font = [UIFont systemFontOfSize:.04*WIDTHDiv];
                }
            }
            
            
            
        }
        
        //视频
        {
            UIView *playerView = [_conView viewWithTag:1999];
            playerView.frame = CGRectMake(0, 0, WIDTHDiv, WIDTHDiv*9/16.0);
            
            for (int i = 0; i < 2; i++) {
                UILabel *clab = [_conView viewWithTag:1000+i];
//                clab.backgroundColor = [UIColor redColor];
                UIImageView *img = [_conView viewWithTag:2000+i];

                
                if (i == 0) {
                    
                    img.frame = CGRectMake(0.02*WIDTHDiv, playerView.zf_bottom+.04*WIDTHDiv, .01*WIDTHDiv, .04*WIDTHDiv);
                    
                    clab.frame = CGRectMake(img.zf_right+0.02*WIDTHDiv, playerView.zf_bottom+0.02*WIDTHDiv, WIDTHDiv -0.07*WIDTHDiv , .08*WIDTHDiv);
                    clab.font = [UIFont boldSystemFontOfSize:clab.zf_height*.55];
                    
                }else{
                    clab.frame = CGRectMake(img.zf_right+0.02*WIDTHDiv, playerView.zf_bottom+0.13*WIDTHDiv, WIDTHDiv -0.04*WIDTHDiv , .12*WIDTHDiv);
                    clab.font = [UIFont boldSystemFontOfSize:.0325*WIDTHDiv];
                    img.frame = CGRectMake(0.02*WIDTHDiv, clab.zf_bottom+0.02*WIDTHDiv, 0.02*WIDTHDiv+.02*HEIGHTDiv, 0.02*WIDTHDiv+.02*HEIGHTDiv);
                    UIButton *btna = [_conView viewWithTag:3000];
//                    btna.backgroundColor= [UIColor greenColor];
//                    img.backgroundColor= [UIColor greenColor];
                    btna.frame = CGRectMake(WIDTHDiv - 0.02*WIDTHDiv-.03*HEIGHTDiv, clab.zf_bottom+0.02*WIDTHDiv, 0.02*WIDTHDiv+.02*HEIGHTDiv, 0.02*WIDTHDiv+.02*HEIGHTDiv);
                    
                    _listV.frame = CGRectMake(0, btna.zf_bottom, WIDTHDiv, HEIGHTDiv-btna.zf_bottom);
                }
            }
            
            
            
        }
        
        //字幕
        {
            for (int i = 0; i < 2; i++) {
                UILabel *classLab = [_conView viewWithTag:300+i];
                if (i == 0) {
                    classLab.frame = CGRectMake(WIDTHDiv*2+0.02*WIDTHDiv, .04*WIDTHDiv, .01*WIDTHDiv, .04*WIDTHDiv);
                }else{
                    classLab.frame = CGRectMake(WIDTHDiv*2+0.05*WIDTHDiv, 0.02*WIDTHDiv, WIDTHDiv -0.07*WIDTHDiv , .08*WIDTHDiv);
                    classLab.font = [UIFont boldSystemFontOfSize:classLab.zf_height*.75];
                }
            }
            _wordV.frame = CGRectMake(WIDTHDiv*2, .1*WIDTHDiv, WIDTHDiv, .83*HEIGHTDiv-.1*WIDTHDiv);
        }
        
        
    }
    
    
    NSString *srtStr = [NSString setSafeString:_resDic[@"srt"]];
    if (srtStr.length>0) {
        //类型按钮
        for (int i=0 ; i<3; i++) {
            UIButton *btn_type = [_bigView viewWithTag:501+i];
            btn_type.frame = CGRectMake(0.2*WIDTHDiv + i%3*0.2*WIDTHDiv, 0.1*HEIGHTDiv, 0.2*WIDTHDiv, 0.03*HEIGHTDiv);
            if ([btn_type isKindOfClass:[UIButton class]]) {
                if (i == _showType) {
                    [btn_type setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    btn_type.titleLabel.font = [UIFont boldSystemFontOfSize:btn_type.zf_height*0.75];
                }else{
                    [btn_type setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
                    btn_type.titleLabel.font = [UIFont boldSystemFontOfSize:btn_type.zf_height*0.65];
                }
            }
            if (i == 2) {
                btn_type.hidden = NO;
            }
        }
    }else{
        //类型按钮
        for (int i=0 ; i<3; i++) {
            UIButton *btn_type = [_bigView viewWithTag:501+i];
            btn_type.frame = CGRectMake(0.3*WIDTHDiv + i%3*0.2*WIDTHDiv, 0.1*HEIGHTDiv, 0.2*WIDTHDiv, 0.03*HEIGHTDiv);
            if ([btn_type isKindOfClass:[UIButton class]]) {
                if (i == _showType) {
                    [btn_type setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    btn_type.titleLabel.font = [UIFont boldSystemFontOfSize:btn_type.zf_height*0.75];
                }else{
                    [btn_type setTitleColor:[UIColor colorWithWhite:.8 alpha:1] forState:UIControlStateNormal];
                    btn_type.titleLabel.font = [UIFont boldSystemFontOfSize:btn_type.zf_height*0.65];
                }
            }
            if (i == 2) {
                btn_type.hidden = YES;
            }
        }
    }
    
    //在什么类型视图
    UIButton *btn_type = [_bigView viewWithTag:501+_showType];
    UIView *typeBg = [_bigView viewWithTag:500];
    typeBg.frame = CGRectMake(btn_type.zf_left+btn_type.zf_width*.3, btn_type.zf_bottom*1.04, btn_type.zf_width*.4, 0.01*WIDTHDiv);
    _conView.zf_left = -(_showType)*WIDTHDiv;
    typeBg.layer.cornerRadius = typeBg.zf_height/2;
    typeBg.layer.masksToBounds = YES;
    
    NSArray *files = _resDic[@"additional"];
    BOOL isfile = files.count == 0?NO:YES;
    for (int i=0 ; i<2; i++) {
        UIButton *rtopBtn = [_bigView viewWithTag:800+i+9];
        
        if (i == 0) {
            rtopBtn.frame = CGRectMake(isfile?WIDTHDiv*.68:WIDTHDiv*.88, backbtn.zf_top, .08*WIDTHDiv, .08*WIDTHDiv);
        }else{
            rtopBtn.hidden = !isfile;
            rtopBtn.frame = CGRectMake(WIDTHDiv*.78, backbtn.zf_top, .2*WIDTHDiv, .08*WIDTHDiv);
            rtopBtn.layer.cornerRadius = .04*WIDTHDiv;
            rtopBtn.layer.masksToBounds = YES;
            
            UIImageView *img = [rtopBtn viewWithTag:770];
            img.frame = CGRectMake(.02*WIDTHDiv, .015*WIDTHDiv, .05*WIDTHDiv, .05*WIDTHDiv);
            UILabel *rtlab = [rtopBtn viewWithTag:780];
            rtlab.frame = CGRectMake(.07*WIDTHDiv, 0, .12*WIDTHDiv, .08*WIDTHDiv);
            rtlab.font = [UIFont systemFontOfSize:.04*WIDTHDiv];
        }
    }
    
    for (int i = 0; i < 3; i++) {
        UIView *contextV = [_audioMutView viewWithTag:680+i];
        
        NSArray *additionals = _resDic[@"additional"];
        NSArray *lables = _resDic[@"lable"];
        NSString *introduce = [NSString setSafeString:_resDic[@"introduce"]];
        float addH = 0;
        if (additionals.count < 4) {
            addH = AUDIOLABH*1.2;
        }else if (additionals.count > 3){
            addH = AUDIOLABH*2.2;
        }
        float labH = 0;
        if (lables.count < 4) {
            labH = AUDIOLABH*1.2;
        }else if (lables.count > 3){
            labH = AUDIOLABH*2.2;
        }
        
        float jianxi = ((WIDTHDiv - AUDIOLABH*2)-AUDIOLABH*2.5*3)/3;
        
        if (i == 0) {
            if (introduce.length == 0) {
                contextV.hidden = YES;
            }else{
                contextV.hidden = NO;
                contextV.frame = CGRectMake(0, 0, WIDTHDiv, _audioMutView.zf_height - addH - labH);
                _contentTextView.frame = CGRectMake(0, 0, contextV.zf_width, contextV.zf_height);
            }
        }else if (i == 1){
            if (additionals.count == 0) {
                contextV.hidden = YES;
            }else{
                contextV.hidden = NO;
                contextV.frame = CGRectMake(0, _contentTextView.zf_bottom, WIDTHDiv, addH);
                
                UILabel *additionalLab = [contextV viewWithTag:639];
                additionalLab.frame = CGRectMake(AUDIOLABH*.2, AUDIOLABH*.1, AUDIOLABH*1.6, AUDIOLABH);
                additionalLab.font = [UIFont boldSystemFontOfSize:AUDIOLABH*.525];
                for (int j = 0; j < additionals.count; j++) {
                    if (j < 6) {
                        UIButton *additionalbtn = [contextV viewWithTag:630+j];
                        additionalbtn.backgroundColor = [UIColor colorWithWhite:0 alpha:.35];
                        
                        additionalbtn.frame = CGRectMake(AUDIOLABH*2+j%3*(jianxi+AUDIOLABH*2.5), AUDIOLABH*.2+j/3*(AUDIOLABH*1.0), AUDIOLABH*2.5, AUDIOLABH*.8);
                        additionalbtn.titleLabel.font = [UIFont boldSystemFontOfSize:additionalbtn.zf_height*.5];
                        additionalbtn.layer.cornerRadius = additionalbtn.zf_height/2;
                        additionalbtn.layer.masksToBounds = YES;
                    }
                }
            }
        }else{
            UIView *contextV1 = [_audioMutView viewWithTag:681];
            if (lables.count == 0) {
                contextV.hidden = YES;
            }else{
                contextV.hidden = NO;
                contextV.frame = CGRectMake(0, contextV1.zf_bottom, WIDTHDiv, labH);
                UILabel *labLab = [contextV viewWithTag:649];
                labLab.frame = CGRectMake(AUDIOLABH*.2, AUDIOLABH*.1, AUDIOLABH*1.6, AUDIOLABH);
                labLab.font = [UIFont boldSystemFontOfSize:AUDIOLABH*.525];
                for (int j = 0; j < lables.count; j++) {
                    if (j < 6) {
                        UIButton *labbtn = [contextV viewWithTag:640+j];
                        labbtn.backgroundColor = [UIColor colorWithWhite:0 alpha:.35];
                        labbtn.frame = CGRectMake(AUDIOLABH*2+j%3*(jianxi+AUDIOLABH*2.5), AUDIOLABH*.2+j/3*(AUDIOLABH*1.0), AUDIOLABH*2.5, AUDIOLABH*.8);
                        labbtn.titleLabel.font = [UIFont boldSystemFontOfSize:labbtn.zf_height*.5];
                        labbtn.layer.cornerRadius = labbtn.zf_height/2;
                        labbtn.layer.masksToBounds = YES;
                    }
                }
                
                
            }
        }
        
        
    }
    
    if (_layoutType == 2) {
        [UIView animateWithDuration:.25 animations:^{
            self.frame = CGRectMake(WIDTHDiv - HEIGHTDiv*.066, SCREEN_HEIGHT - GCtabbarHeight -  HEIGHTDiv*.066 , HEIGHTDiv*.066, HEIGHTDiv*.066);
            self->_smallView.backgroundColor = [UIColor clearColor];
        }];
    }
    if (_layoutType == 1) {
        [UIView animateWithDuration:.25 animations:^{
            self.frame = CGRectMake(0, SCREEN_HEIGHT - GCtabbarHeight -  HEIGHTDiv*.066 , WIDTHDiv, HEIGHTDiv*.066);
            self->_smallView.frame = CGRectMake(0, 0, WIDTHDiv, HEIGHTDiv*.066);
            self->_smallView.backgroundColor = [UIColor colorWithHex:@"#F4F4F4"];
            if (![GCAVPlayer shared].isAudio) {
                    [GCAVPlayer shared].playerLayer.frame = CGRectMake(0, 0, (HEIGHTDiv*.066*.8)/(9/16.0), HEIGHTDiv*.066*.8);
//                [GCAVPlayer shared].playerLayer.frame = CGRectMake(0, 0, 100, 100);
            }
            [self refreshType1];
        }];
        [UIView animateWithDuration:.35 animations:^{
            self->_bigView.frame = CGRectMake(0, HEIGHTDiv, WIDTHDiv, HEIGHTDiv);
        }];
    }
    if (_layoutType == 3) {
        self.frame = CGRectMake(0, 0, WIDTHDiv, HEIGHTDiv);
        _smallView.frame = CGRectMake(0, HEIGHTDiv- GCtabbarHeight -  HEIGHTDiv*.066, WIDTHDiv, HEIGHTDiv*.066);
        [UIView animateWithDuration:.25 animations:^{
            self->_smallView.frame = CGRectMake(0, HEIGHTDiv, WIDTHDiv, HEIGHTDiv*.066);
        }];
        [UIView animateWithDuration:.35 animations:^{
            self->_bigView.frame = CGRectMake(0, 0, WIDTHDiv, HEIGHTDiv);
        }];
    }
}

-(void)refreshType1{
    self.frame = CGRectMake(0, SCREEN_HEIGHT - GCtabbarHeight -  HEIGHTDiv*.066 , WIDTHDiv, HEIGHTDiv*.066);
    _smallView.frame = CGRectMake(0, 0, self.zf_width, self.zf_height);
    _resbtn.frame = _smallView.frame;
    _svideoplayView.frame = CGRectMake(self.zf_height*.1, self.zf_height*.1, self.zf_height*.8/(9/16.0), self.zf_height*.8);
    _svideoplayView.layer.cornerRadius = self.zf_height*.1;
    _svideoplayView.layer.masksToBounds = YES;
    for (int i  = 0; i < 3; i++) {
        GCButton *btn = [_smallView viewWithTag:100+i];
        
        UILabel *lab = [_smallView viewWithTag:200+i];
        
        switch (i) {
            case 0:
                btn.frame = CGRectMake(self.zf_height*.05, self.zf_height*.05, self.zf_height*.9, self.zf_height*.9);
                if ([GCAVPlayer shared].isAudio) {
                    _svideoplayView.hidden = YES;
                    btn.hidden = NO;
                }else{
                    _svideoplayView.hidden = NO;
                    btn.hidden = YES;
                }
                btn.layer.cornerRadius = self.zf_height*.45;
                btn.layer.masksToBounds = YES;
                
                lab.frame = CGRectMake(([GCAVPlayer shared].isAudio?btn.zf_right:_svideoplayView.zf_right)+self.zf_height*.1, self.zf_height*.05, (self.zf_width-([GCAVPlayer shared].isAudio?self.zf_height:self.zf_height*.8/(9/16.0)+self.zf_height*.2)-self.zf_height*1.6)/*/2*/, self.zf_height*.425);
                lab.font = [UIFont systemFontOfSize:self.zf_height*.3];
                
                break;
            case 1:
            {
                btn.frame = CGRectMake(self.zf_width - self.zf_height*1.6, self.zf_height*.2, self.zf_height*.6, self.zf_height*.6);
                _dview.frame = CGRectMake(btn.zf_left-1, btn.zf_top-1, btn.zf_width+2, btn.zf_height+2);
                
                _actView.frame = btn.frame;
                
                GCButton *btn1 = [_smallView viewWithTag:100];
                lab.frame = CGRectMake(([GCAVPlayer shared].isAudio?btn1.zf_right:_svideoplayView.zf_right)+self.zf_height*.1, self.zf_height*.55, (self.zf_width-([GCAVPlayer shared].isAudio?self.zf_height:self.zf_height*.8/(9/16.0)+self.zf_height*.1)-self.zf_height*1.6)/*/2*/, self.zf_height*.425);
                lab.font = [UIFont systemFontOfSize:self.zf_height*.22];
            }
                
                break;
            case 2:
                btn.frame = CGRectMake(self.zf_width - self.zf_height*.8, self.zf_height*.2, self.zf_height*.6, self.zf_height*.6);
//                UILabel *lab1 = [_smallView viewWithTag:200];
//                lab.frame = CGRectMake(lab1.zf_right+self.zf_width*.01, self.zf_height*.55, (self.zf_width-self.zf_height-self.zf_height*1.6)/2, self.zf_height*.425);
//                lab.font = [UIFont systemFontOfSize:self.zf_height*.32];
                break;
        }
        
    }
    
    
}


@end





@interface GCAVPlayer ()<audioPlayerViewDelegate,TYDownloadDelegate>

@property(nonatomic,strong)audioPlayerView *apView;





@property (nonatomic ,readonly) AVPlayerItem *item;



@property(nonatomic,strong)NSString *playerUrl;

@property(nonatomic,strong)NSMutableArray *datas;
@property(nonatomic,strong)NSDictionary *resDic;
@property(nonatomic,strong)NSArray *playlistDatas;

@property (nonatomic ,strong)  id timeObser;



@property (nonatomic ,assign) float playrate;
@property (nonatomic ,assign) float endplayrate;
@property (nonatomic, strong) ObjectAFNetWorking* objectAFN;

@property(nonatomic,strong)NSMutableArray *wordtimes;
@property(nonatomic,strong)NSMutableArray *words;

@property(nonatomic,assign)BOOL isNeedWord;

@end

@implementation GCAVPlayer

-(audioPlayerView *)apView{
    if (!_apView) {
        _apView = [audioPlayerView new];
        _apView.delegate = self;
    }
    return _apView;
}

-(void)smallBtnClickWithTag:(NSInteger)tag{
    switch (tag) {
        case 0:
            
            break;
        case 1:
            if (_player.rate == 0) {
                [self play];
            }else{
                [self pause];
            }
            break;
        case 2:
        {
            PlayListView *listView  = [[PlayListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
           
            UIView *superView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
            if (!superView) {
                superView = [UIApplication sharedApplication].keyWindow;
            }
            
            [listView showIn:[[[UIApplication sharedApplication] delegate] window] listArray:_playlistDatas IdStr:_playlistDatas[_index][@"id"]];
            
            NSArray *titleArray = [[NSString setSafeString:_resDic[@"media_class_name"]] componentsSeparatedByString:@"|"];
            if (titleArray.count >= 2) {
                
                listView.subTitleStr = titleArray[1];
            }
        }
            break;
    }
}

-(void)bigBtnClickWithTag:(NSInteger)tag{
    NSLog(@"tag~~~>>%zd",tag);
    switch (tag) {
        case 0:
//        已处理
            break;
        case 1:
//        已处理
            break;
        case 2:
        {
            PlayCountDownView *view = [[PlayCountDownView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
//            self.countDownView = view;
//            view.mulitStr = self.countDownType;
            view.countDownIndexBlock = ^(NSInteger index) {
//                [self timeBtnSelectAction:index];
//                self.countDownType = self->_timeListNameArray[index];
//                [self timeListMaskViewTapAction];
                NSLog(@"indexindex~~~~~>>%zd",index);
            };
            view.dataSource = @[@"不开启",@"10分钟后",@"20分钟后",@"30分钟后",@"60分钟后",@"90分钟后",@"播完当前音频后"];;
            UIView *superView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
            if (!superView) {
                superView = [UIApplication sharedApplication].keyWindow;
            }
            [view showIn:[[[UIApplication sharedApplication] delegate] window] muliter:@""];
        }
            break;
        case 3:
        {
            PlayListView *listView  = [[PlayListView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
           
            UIView *superView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
            if (!superView) {
                superView = [UIApplication sharedApplication].keyWindow;
            }
            
            [listView showIn:[[[UIApplication sharedApplication] delegate] window] listArray:_playlistDatas IdStr:_playlistDatas[_index][@"id"]];
            
            NSArray *titleArray = [[NSString setSafeString:_resDic[@"media_class_name"]] componentsSeparatedByString:@"|"];
            if (titleArray.count >= 2) {
                
                listView.subTitleStr = titleArray[1];
            }
        }
            break;
        case 4:
            [self lastPlay];
            break;
        case 5:
            NSLog(@"_player.rate~~>>%lf",_player.rate);
            if (_player.rate == 0) {
                [self play];
            }else{
                [self pause];
            }
            break;
        case 6:
            [self nextPlay];
            break;
        case 7:
            [self retreatQuickly];
            break;
        case 8:
            [self fastForward];
            break;
        case 9:
        {
            
            
            if ([[Cache shared] user_id]&&[[Cache shared] user_id].length>0) {
                
                UserModel *userM =  [[Cache shared] userInfo];
                
                
                NSString *url = [NSString stringWithFormat:@"%@/api/collect/setCollect",server_addr];
                NSLog(@"detailsDic~~>>%@",url);
                
                [_objectAFN postUrlStr:url parames:@{@"media_id":_media_id,@"user_id":[[Cache shared] user_id]} finish:^(id  _Nonnull dataString) {
                    NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];

                    NSLog(@"getonecollect~~~>>%@",detailsDic);
                    if ([[NSString setSafeString:detailsDic[@"code"]] intValue] == 1) {
                        _iscollect = [[NSString setSafeString:detailsDic[@"data"][@"type"]] boolValue];
                    }else{
                        
                    }
                    _apView.iscollect = _iscollect;
                    
                    } andError:^(NSError * _Nonnull error) {
                        
                        
                }];
            }else{
                [_apView backbtnClick];
                LoginViewController *lc = [LoginViewController new];
                lc.isplayskip = 100;
                [[UIViewController currentViewController].navigationController pushViewController:lc animated:YES];
            }
            
        }
            break;
        case 10:
            
            break;
    }
}

-(void)showpppLoginplayer{
    [_apView showLoginplayer];
}

static GCAVPlayer *sharedRTab = nil;

+ (GCAVPlayer *)shared{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedRTab = [[super allocWithZone:nil]init];
        
    });
    
    return sharedRTab;
}

+(id)allocWithZone:(NSZone *)zone
{
    return [GCAVPlayer shared];
}

-(id)copy
{
    return self;
}

- (id)copyWithZone:(NSZone *)zone
{
    return self;
}

-(void)pause{
    [self.player pause];
}

-(void)play{
    _player.rate = _gc_rate;
    [self.player play];
}

-(void)nextPlay{
    if (_playStyle == playTypeSingle || _playStyle == playTypeSequence) {
        _index++;
        if (_index >_playlistDatas.count-1) {
            _index = 0;
        }
    }else if (_playStyle == playTypeRandom) {
        _index = arc4random()%_playlistDatas.count;
    }
    [self playIndex:_index];
}

-(void)lastPlay{
    if (_playStyle == playTypeSingle || _playStyle == playTypeSequence) {
        _index--;
        if (_index < 0) {
            _index = _playlistDatas.count-1;
        }
    }else if (_playStyle == playTypeRandom) {
        _index = arc4random()%_playlistDatas.count;
    }
    [self playIndex:_index];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _index = 0;
        _isNeedWord = NO;
        _iscollect = NO;
        _playStyle = playTypeSequence;
        _datas = NSMutableArray.array;
        _words = NSMutableArray.array;
        _wordtimes = NSMutableArray.array;
        _objectAFN = [ObjectAFNetWorking new];
        [[UIApplication sharedApplication].keyWindow addSubview:self.apView];
//        _apView.layer.zPosition = 0;
        [NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(isplayrate) userInfo:nil repeats:YES];
    }
    return self;
}

-(void)isplayrate{
    _playrate = _player.rate;
    if (_playrate != _endplayrate) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"GCplayertype" object:nil userInfo:@{@"info":@(_playrate==0?NO:YES)}];
        [_apView viewisPlay:_playrate==0?NO:YES];
        if ([self.delegate respondsToSelector:@selector(isPlay:)]) {
            if (_playrate != 0) {
                [self.delegate isPlay:YES];
                
            }else{
                [self.delegate isPlay:NO];
            }
        }
    }
    _endplayrate = _player.rate;
}

-(void)playvideo{
    if([self determineNetwork] != 0){
        [self removeVideoTimerObserver];
        [self removeVideoNotic];
        [self removeVideoKVO];
        
        NSURL *url = [NSURL fileURLWithPath:_playerUrl];
                
        AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:url];
        if (self.player == nil) {
            self.player = [[AVPlayer alloc]initWithPlayerItem:item];
        }else {
            [self.player replaceCurrentItemWithPlayerItem:item];
        }
        _item = item;
//            _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
//            _playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
//            [_apView.bigView.layer addSublayer:_playerLayer];
//            _playerLayer.frame = CGRectMake(0, 0, 100, 100);
        
        

        [self addVideoKVO];
        [self addVideoNotic];
        [self addVideoTimerObserver];

        if (self.player.rate == 0 ) {
            [self createRemoteCommandCenter];
            [self.player play];
            if ([self.delegate respondsToSelector:@selector(startCache)]) {
                [self.delegate startCache];
            }
        }
    }
}

typedef void (^srtfileBack)(NSString *obj);

-(void)dealWithSubtitles:(NSDictionary *)detailsDic andid:(NSString *)audio_id andback:(srtfileBack)call{
    _resDic = detailsDic;
    NSString *srtStr = [NSString setSafeString:detailsDic[@"file"]];
    if (srtStr.length == 0) {
        call(@"");
        return;
    }
    
    NSString*testDirectory = [self GetdocumentsDirectory];
    testDirectory = [testDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/gcSrt/"]];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager createDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
    testDirectory = [testDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.srt",audio_id]];
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:testDirectory]) {
        NSString *str = [NSString stringWithContentsOfFile:testDirectory encoding:NSUTF8StringEncoding error:nil];
        call(str);
    }else{
        srtStr = [srtStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        TYDownloadModel *model = [[TYDownloadModel alloc]initWithURLString:srtStr filePath:testDirectory];
        TYDownLoadDataManager *manager = [TYDownLoadDataManager manager];
        
        [manager startWithDownloadModel:model progress:^(TYDownloadProgress *progress) {
            NSLog(@"progress->>%lf",progress.progress);
            
        } state:^(TYDownloadState state, NSString *filePath, NSError *error) {
            
            if (state == TYDownloadStateCompleted) {
                NSString *str = [NSString stringWithContentsOfFile:testDirectory encoding:NSUTF8StringEncoding error:nil];
                call(str);
            }
        }];
    }
}

-(NSString *)timeTrans:(NSString *)time{
    NSString *a = [[time componentsSeparatedByString:@","] firstObject];
    NSString *a1 = [[time componentsSeparatedByString:@","] lastObject];
    NSArray *aa = [a componentsSeparatedByString:@":"];
    float b = [[aa lastObject] floatValue];
    float c = [aa[1] floatValue]*60;
    float d = [aa[0] floatValue]*60*60;
    float e = b+c+d;
    NSString *f = [NSString stringWithFormat:@"%.0lf",e];
    NSString *g = [NSString stringWithFormat:@"%@.%@",f,a1];
    NSString *h = [NSString stringWithFormat:@"%.1lf",[g floatValue]];
    return h;
}

-(void)determineTypeOfVideoPlay:(NSDictionary *)detailsDic andid:(NSString *)player_id{
    
    if ([NSString setSafeString:detailsDic[@"video_url"]].length>0) {
        
        _isAudio = NO;
        if (_apView.layoutType == 3) {
            _apView.showType = 0;
            [self setNeedsLayout];
        }
        [self playUrl:[SqliteHelp takeAudioDicWithid:player_id][@"video_url"] ad:player_id];
    }else{
        _isAudio = YES;
        [self playUrl:detailsDic[@"audio_url"] ad:player_id];
        
    }
    _apView.resDic = detailsDic;
}

-(void)determineTypeOfPlay:(NSDictionary *)detailsDic andid:(NSString *)player_id{
    
    [toolHelp saveHistoryData:detailsDic andID:player_id];
    
    _media_id = player_id;
    
//
    NSString *url = [NSString stringWithFormat:@"%@/api/collect/getonecollect",server_addr];
    NSLog(@"detailsDic~~>>%@",url);
    [_objectAFN postUrlStr:url parames:@{@"media_id":_media_id,@"user_id":[[Cache shared] user_id]} finish:^(id  _Nonnull dataString) {
        NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];

        self->_iscollect = [[NSString setSafeString:detailsDic[@"status"]] boolValue];
        
        self->_apView.iscollect = self->_iscollect;
        
        } andError:^(NSError * _Nonnull error) {
            NSLog(@"~~~~1`~>>%@",error);
    }];
    
    [self dealWithSubtitles:detailsDic andid:player_id andback:^(NSString *obj) {
        
        if (obj.length>0) {
            self->_isNeedWord = YES;
            NSArray *ci = [obj componentsSeparatedByString:@"\n"];
            
            
            for (int i = 0; i < ci.count; i++) {
                NSString *a = ci[i];
                a = [a stringByReplacingOccurrencesOfString:@"\r" withString:@""];
                if (i%4 == 1) {
                    NSArray *b = [a componentsSeparatedByString:@" --> "];
                    NSString *c = [b firstObject];
                    NSString *d = [b lastObject];
                    NSString *e = [self timeTrans:c];
                    NSString *f = [self timeTrans:d];
                    NSString *g = [NSString stringWithFormat:@"%@-%@",e,f];
                    
                    [self->_wordtimes addObject:g];
                }
                if (i%4 == 2) {
                    [self->_words addObject:a];
                }
            }
            [self->_apView.wordV setHidden:NO];
            self->_apView.wordV.timeDatas = self->_wordtimes.mutableCopy;
            self->_apView.wordV.datas = self->_words.mutableCopy;
        }else{
            self->_isNeedWord = NO;
            [self->_apView.wordV.timeDatas removeAllObjects];
            [self->_apView.wordV.datas removeAllObjects];
            [self->_apView.wordV.tableView reloadData];
            [self->_apView.wordV setHidden:YES];
            [self->_wordtimes removeAllObjects];
            [self->_words removeAllObjects];
        }
    }];
    
    
    if ([NSString setSafeString:detailsDic[@"audio_url"]].length>0) {
        _isAudio = YES;
        [self playUrl:detailsDic[@"audio_url"] ad:player_id];
        
    }else{
        _isAudio = NO;
        if (_apView.layoutType == 3) {
            _apView.showType = 0;
            [self setNeedsLayout];
        }
        [self playUrl:[SqliteHelp takeAudioDicWithid:player_id][@"video_url"] ad:player_id];
        
    }
    _apView.resDic = detailsDic;
}

-(void)playVideoIndex:(NSInteger)index{
    _apView.listV.selectNum = index;
    NSString *player_id = [NSString setSafeString:_playlistDatas[index][@"id"]];
    if ([SqliteHelp isSaveAudiodicWithid:player_id]) {
        NSDictionary *detailsDic = [SqliteHelp takeAudioDicWithid:player_id];
        if ([NSString setSafeString:detailsDic[@"introduce"]].length>0) {
            [_objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatedetail?id=%@",server_addr,player_id] finish:^(id  _Nonnull dataString) {
                
                NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
                
                [self determineTypeOfPlay:[NSDictionary setSafeDictionary:detailsDic[@"data"]] andid:player_id];
            
                
            } andError:^(NSError * _Nonnull error) {
                NSLog(@"~~~>>%@",@"");
            }];
        }else{
            [self determineTypeOfPlay:detailsDic andid:player_id];
        }
        
        
        
    }else{
        [_objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatedetail?id=%@",server_addr,player_id] finish:^(id  _Nonnull dataString) {
            
            NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
            
            [self determineTypeOfVideoPlay:[NSDictionary setSafeDictionary:detailsDic[@"data"]] andid:player_id];
        
            [SqliteHelp saveAudioDicWith:[NSDictionary setSafeDictionary:detailsDic[@"data"]]];
            
        } andError:^(NSError * _Nonnull error) {
            NSLog(@"~~~>>%@",@"");
        }];
    }
}

-(void)playIndex:(NSInteger)index{
    _apView.listV.selectNum = index;
    NSString *player_id = [NSString setSafeString:_playlistDatas[index][@"id"]];
    
    if ([SqliteHelp isSaveAudiodicWithid:player_id]) {
        NSDictionary *detailsDic = [SqliteHelp takeAudioDicWithid:player_id];
        if ([NSString setSafeString:detailsDic[@"introduce"]].length>0) {
            [_objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatedetail?id=%@",server_addr,player_id] finish:^(id  _Nonnull dataString) {
                
                NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
                
                [self determineTypeOfPlay:[NSDictionary setSafeDictionary:detailsDic[@"data"]] andid:player_id];
            
                
            } andError:^(NSError * _Nonnull error) {
                NSLog(@"~~~>>%@",@"");
            }];
        }else{
            [self determineTypeOfPlay:detailsDic andid:player_id];
        }
        
        
        
    }else{
        [_objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatedetail?id=%@",server_addr,player_id] finish:^(id  _Nonnull dataString) {
            
            NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
            
            [self determineTypeOfPlay:[NSDictionary setSafeDictionary:detailsDic[@"data"]] andid:player_id];
        
            [SqliteHelp saveAudioDicWith:[NSDictionary setSafeDictionary:detailsDic[@"data"]]];
            
        } andError:^(NSError * _Nonnull error) {
            NSLog(@"~~~>>%@",@"");
        }];
    }
}

-(void)play:(NSArray *)resArr andindex:(NSInteger)index ViewStatue:(NSInteger)type andIsAudio:(BOOL)isaudio{
    _playlistDatas = resArr.copy;
    _isAudio = isaudio;
    _apView.layoutType = type;
    [_apView setNeedsLayout];
    _apView.listV.selectNum = index;
    _apView.listV.datas = resArr.mutableCopy;
    _index = index;
    NSInteger subtag = [[NSUserDefaults standardUserDefaults] integerForKey:@"gcplaytype"];
    _playStyle = subtag;
    NSLog(@"_apView~~~>>%@",resArr[index]);
    NSString *player_id = [NSString setSafeString:resArr[index][@"id"]];
    if (player_id.length == 0) {
        player_id = [NSString setSafeString:resArr[index][@"media_id"]];
    }
    
    if ([self.delegate respondsToSelector:@selector(playforMedia_id:)]) {
        [self.delegate playforMedia_id:player_id];
    }
    
    if ([SqliteHelp isSaveAudiodicWithid:player_id]) {
        NSDictionary *detailsDic = [SqliteHelp takeAudioDicWithid:player_id];
        
        if ([NSString setSafeString:detailsDic[@"introduce"]].length>0) {
            [_objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatedetail?id=%@",server_addr,player_id] finish:^(id  _Nonnull dataString) {
                
                NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
                
                [self determineTypeOfPlay:[NSDictionary setSafeDictionary:detailsDic[@"data"]] andid:player_id];
            
                
            } andError:^(NSError * _Nonnull error) {
                NSLog(@"~~~>>%@",@"");
            }];
        }else{
            [self determineTypeOfPlay:detailsDic andid:player_id];
        }
        
        
        
    }else{
        [_objectAFN getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatedetail?id=%@",server_addr,player_id] finish:^(id  _Nonnull dataString) {
            
            NSDictionary* detailsDic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
            
            [self determineTypeOfPlay:[NSDictionary setSafeDictionary:detailsDic[@"data"]] andid:player_id];
        
            [SqliteHelp saveAudioDicWith:[NSDictionary setSafeDictionary:detailsDic[@"data"]]];
            
        } andError:^(NSError * _Nonnull error) {
            NSLog(@"~~~>>%@",@"");
        }];
    }
}

-(void)playUrl:(NSString *)url ad:(NSString *)audio_id{
    
    BOOL isDownload = YES;
    if (_isAudio) {
        NSString*testDirectory = [self GetdocumentsDirectory];
        testDirectory = [testDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/gcAudio/"]];
        NSFileManager *fileManager = [NSFileManager defaultManager];
        [fileManager createDirectoryAtPath:testDirectory withIntermediateDirectories:YES attributes:nil error:nil];
        testDirectory = [testDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.mp3",audio_id]];
        
        if ([SqliteHelp isSaveDownloadWithid:audio_id]) {
            _playerUrl = testDirectory;
            isDownload = YES;
        }else{
            isDownload = NO;
            _playerUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            TYDownloadModel *model = [[TYDownloadModel alloc]initWithURLString:_playerUrl filePath:testDirectory];
            TYDownLoadDataManager *manager = [TYDownLoadDataManager manager];
            
            [manager startWithDownloadModel:model progress:^(TYDownloadProgress *progress) {
//                NSLog(@"progress->>%lf",progress.progress);
                
            } state:^(TYDownloadState state, NSString *filePath, NSError *error) {
                if (state == TYDownloadStateCompleted) {
                    NSString *str = [[[[filePath componentsSeparatedByString:@"/"] lastObject] componentsSeparatedByString:@"."] firstObject];
                    [SqliteHelp saveDownloadWith:str];
                    NSLog(@"下载完成~~~~");
                }
            }];
        }
    }
    
    
    if([self determineNetwork] != 0){
        [self removeVideoTimerObserver];
        [self removeVideoNotic];
        [self removeVideoKVO];
        NSURL *url = [NSURL URLWithString:_playerUrl];
        if (!_isAudio) {
//            _playerUrl = @"https://res.tuxiaobei.com/video/ltPfz0_orw_ceCQXD6FoHT2Rq5xl.mp4";
            url = [NSURL URLWithString:_playerUrl];
        }else{
            if (isDownload) {
                url = [NSURL fileURLWithPath:_playerUrl];
            }else{
//                _playerUrl = @"https://res.tuxiaobei.com/video/ltPfz0_orw_ceCQXD6FoHT2Rq5xl.mp4";
                url = [NSURL URLWithString:_playerUrl];
                [_apView startLoading];
            }
        }

        AVPlayerItem *item = [[AVPlayerItem alloc]initWithURL:url];
        if (self.player == nil) {
            self.player = [[AVPlayer alloc]initWithPlayerItem:item];
        }else {
            [self.player replaceCurrentItemWithPlayerItem:item];
        }
        
        _item = item;
        if (!_isAudio) {
            _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
            _playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
            [_apView.videoplayView.layer addSublayer:_playerLayer];
            _playerLayer.frame = CGRectMake(0, 0, WIDTHDiv, WIDTHDiv*9/16.0);
        }else{
            if (_playerLayer) {
                _playerLayer.player = nil;
                [_playerLayer removeFromSuperlayer];

            }
        }
        
        [self addVideoKVO];
        [self addVideoNotic];
        [self addVideoTimerObserver];

        if (self.player.rate == 0 ) {
            [self createRemoteCommandCenter];
            [self.player play];
            
            if ([self.delegate respondsToSelector:@selector(startCache)]) {
                [self.delegate startCache];
            }
        }
    }
}

-(void)slierChange:(float)progress{
//    NSLog(@"slierChange~~~~>>>>>>%lf",progress);
    [self seekToTime:progress*_videoLength completionHandler:^(BOOL finished) {
        [self play];
    }];
}

-(void)moveslier:(BOOL)ismoveslier{
//    NSLog(@"~~~~>>%@",ismoveslier?@"yyyyyyy":@"nnnnnnnn");
    if (ismoveslier) {
        [self pause];
    }
}

-(void)seekToTime:(NSTimeInterval)progress completionHandler:(void (^ __nullable)(BOOL finished))completionHandler{
    CMTime seekTime = CMTimeMake(progress, 1);
//    [_playerItem cancelPendingSeeks];
    [_player seekToTime:seekTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:completionHandler];
}

-(void)retreatQuickly{
    Float64 cur =  CMTimeGetSeconds(_player.currentTime);
                    cur -= 10;
    [_player seekToTime:CMTimeMake(cur, 1)];
    _player.rate = _gc_rate;
    [_player play];
}

-(void)fastForward{
    Float64 cur =  CMTimeGetSeconds(_player.currentTime);
                    cur += 10;
    [_player seekToTime:CMTimeMake(cur, 1)];
    _player.rate = _gc_rate;
    [_player play];
}

-(void)setListDatas:(NSArray *)listDatas{
    _listDatas = listDatas;
    _datas = _listDatas.mutableCopy;
}

- (void)addVideoKVO
{
    //KVO
    [_item addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [_item addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];
    [_item addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)removeVideoKVO {
    [_item removeObserver:self forKeyPath:@"status"];
    [_item removeObserver:self forKeyPath:@"loadedTimeRanges"];
    [_item removeObserver:self forKeyPath:@"playbackBufferEmpty"];
}

- (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary<NSString*, id> *)change context:(nullable void *)context {
    
    if ([keyPath isEqualToString:@"status"]) {
        AVPlayerItemStatus status = _item.status;
        switch (status) {
            case AVPlayerItemStatusReadyToPlay:
            {
                NSLog(@"AVPlayerItemStatusReadyToPlay");
//                float rate = [[NSString stringWithFormat:@"%.1lf",[[[NSUserDefaults standardUserDefaults] valueForKey:@"playbeishu"] floatValue]] floatValue];
//                _gc_rate = rate;
                
                NSString *seektime = [NSString setSafeString:_resDic[@"start_skip_time"]];
                if (seektime&&seektime.length>0) {
                    NSArray *ass = [seektime componentsSeparatedByString:@":"];
                    if (ass.count >= 3) {
                        float timef1 = [ass[0] floatValue]*60*60;
                        float timef2 = [ass[1] floatValue]*60;
                        float timef3 = ass[2]?[ass[2] floatValue]:0.00;
                        float timef4 = timef1+timef2+timef3;
                        [self seekToTime:timef4 completionHandler:^(BOOL finished) {
                            
                        }];
                    } else {
                        float timef1 = [ass[0] floatValue]*60*60;
                        float timef2 = [ass[1] floatValue]*60;
                        float timef4 = timef1+timef2;
                        [self seekToTime:timef4 completionHandler:^(BOOL finished) {
                            
                        }];
                    }
                }
                
                [self play];
                [_apView viewisPlay:YES];
                [_apView startPlay];
                if ([self.delegate respondsToSelector:@selector(isPlay:)]) {
                    [self.delegate isPlay:YES];
                }
//                _videoLength = floor(_item.asset.duration.value *1.0/ _item.asset.duration.timescale);
                _videoLength = _isAudio?[[NSString setSafeString:_resDic[@"audio_num"]] floatValue]:[[NSString setSafeString:_resDic[@"video_num"]] floatValue];
                _endtimestr = [self getVideoLengthFromTimeLength:_videoLength];
                if ([self.delegate respondsToSelector:@selector(startPlay)]) {
                    [self.delegate startPlay];
                }
//                __weak typeof (self)_self = self;
//                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
//                    //显示锁屏播放信息
//                    ICMusicPlayModel *model = _self.audioModel;
//                    if (model == nil) return;
//                    NSMutableDictionary * musicDic = [[NSMutableDictionary alloc] init];
//                    //设置歌曲题目
//                    [musicDic setObject:model.name ?: @"" forKey:MPMediaItemPropertyTitle];
//                    //设置歌手名
//                    NSString *teacherName = model.teacher_name ?: @"" ;
//                    [musicDic setObject:teacherName forKey:MPMediaItemPropertyArtist];
//                    //设置专辑名
//                    //        [musicDic setObject:@"专辑名" forKey:MPMediaItemPropertyAlbumTitle];
//                    //设置歌曲时长
//                    [musicDic setObject:[NSNumber numberWithDouble:_self.videoLength]  forKey:MPMediaItemPropertyPlaybackDuration];
//                    //设置已经播放时长
//                    [musicDic setObject:[NSNumber numberWithDouble:0] forKey:MPNowPlayingInfoPropertyElapsedPlaybackTime];
//                    //设置播放速率
//                    [musicDic setObject:[NSNumber numberWithInteger:_self.player.rate] forKey:MPNowPlayingInfoPropertyPlaybackRate];
//                    //设置显示的海报图片
//                    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.image]] scale:1];
//                    if (image == nil) {
//                        image = [UIImage imageNamed:@"default"];
//                    }
//                    [musicDic setObject:[[MPMediaItemArtwork alloc] initWithImage:image]
//                                 forKey:MPMediaItemPropertyArtwork];
//                    [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:musicDic];
//                });
                
            }
                break;
            case AVPlayerItemStatusUnknown:
            {
                NSLog(@"AVPlayerItemStatusUnknown");
            }
                break;
            case AVPlayerItemStatusFailed:
            {
//                NSLog(@"AVPlayerItemStatusFailed");
//                NSLog(@"%@",_item.error);
//                [MBProgressHUD showMessageBlack:@"加载视屏数据失败,请稍后再试" inView:self];
            }
                break;
                
            default:
                break;
        }
    } else if ([keyPath isEqualToString:@"loadedTimeRanges"]) {
        NSTimeInterval timeInterval = [self availableDuration];// 计算缓冲进度

        CMTime duration = _item.duration;
        CGFloat totalDuration = CMTimeGetSeconds(duration);
        
        _cacheproress = timeInterval/totalDuration;
        [_apView updatecacheProgress:_cacheproress];
//        NSLog(@"_---->%@",self.player.rate != 0?@"播放":@"没哟");
//        NSLog(@"Time _cacheproress:%f",_cacheproress);
        if (_player.rate != 0) {
            if ([self.delegate respondsToSelector:@selector(cacheProgress:playProgress:)]) {
                [self.delegate cacheProgress:_cacheproress playProgress:_proproress];
            }
        }
        
    } else if ([keyPath isEqualToString:@"playbackBufferEmpty"]) {
        NSLog(@"playbackBufferEmpty");
    }
}

- (NSTimeInterval)availableDuration {
    NSArray *loadedTimeRanges = [[_player currentItem] loadedTimeRanges];
    CMTimeRange timeRange = [loadedTimeRanges.firstObject CMTimeRangeValue];// 获取缓冲区域
    float startSeconds = CMTimeGetSeconds(timeRange.start);
    float durationSeconds = CMTimeGetSeconds(timeRange.duration);
    NSTimeInterval result = startSeconds + durationSeconds;// 计算缓冲总进度
    return result;
}

#pragma mark - TimerObserver
- (void)addVideoTimerObserver {
    __weak typeof (self)self_ = self;
    _timeObser = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(.1, NSEC_PER_SEC)  queue:NULL usingBlock:^(CMTime time) {
        float currentTimeValue = time.value*1.0/time.timescale/self_.videoLength;
        
        float atimes = time.value*1.0/time.timescale*10;
        if (self_.isNeedWord) {
            [self_.apView.wordV updatePlayerTime:atimes];
        }
        if((int)atimes%10==0){
            self_.proproress = floor(currentTimeValue*1000) / 1000;
            [self_.apView updateProgress:atimes/10];
            self_.starttimestr = [self_ getStringFromCMTime:time];
            if ([self_.delegate respondsToSelector:@selector(cacheProgress:playProgress:)]) {
                [self_.delegate cacheProgress:self_.cacheproress playProgress:self_.proproress];
            }
//            NSLog(@"Time proproress:%f",atimes);
            float rate = [[NSString stringWithFormat:@"%.1lf",[[[NSUserDefaults standardUserDefaults] valueForKey:@"playbeishu"] floatValue]] floatValue];
            if (self_.player.rate != rate) {
                self_.player.rate = rate;
                [self_ play];
            }
        }
    }];
}

- (void)removeVideoTimerObserver {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    [_player removeTimeObserver:_timeObser];
}

- (void)addVideoNotic {
    
    //Notification
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieToEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieJumped:) name:AVPlayerItemTimeJumpedNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieStalle:) name:AVPlayerItemPlaybackStalledNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backGroundPauseMoive) name:UIApplicationDidEnterBackgroundNotification object:nil];
    
}

- (void)removeVideoNotic {
    //
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemPlaybackStalledNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemTimeJumpedNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (NSString *)getStringFromCMTime:(CMTime)time
{
    float currentTimeValue = (CGFloat)time.value/time.timescale;//得到当前的播放时
    NSDate * currentDate = [NSDate dateWithTimeIntervalSince1970:currentTimeValue];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSInteger unitFlags = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ;
    NSDateComponents *components = [calendar components:unitFlags fromDate:currentDate];
    
//    if (currentTimeValue >= 3600 ){
//        return [NSString stringWithFormat:@"%ld:%ld:%ld",components.hour,components.minute,components.second];
//    }else{
    
    return [NSString stringWithFormat:@"%zd:%@",components.minute,components.second < 10?[NSString stringWithFormat:@"0%zd",components.second]:[NSString stringWithFormat:@"%zd",components.second]];
//    }
}

- (NSString *)getVideoLengthFromTimeLength:(float)timeLength{
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:timeLength];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSInteger unitFlags = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ;
    NSDateComponents *components = [calendar components:unitFlags fromDate:date];

        return [NSString stringWithFormat:@"%zd:%@",components.minute,components.second < 10?[NSString stringWithFormat:@"0%zd",components.second]:[NSString stringWithFormat:@"%zd",components.second]];
}

- (void)movieToEnd:(NSNotification *)notic {
    
    if ([self.delegate respondsToSelector:@selector(playEnd)]) {
        [self.delegate playEnd];
    }
    
    if (_playStyle == 0 || _playStyle == 2) {
        [self nextPlay];
    }else{
        [self playIndex:_index];
    }
    
}
- (void)movieJumped:(NSNotification *)notic {
//    NSLog(@"%@",NSStringFromSelector(_cmd));
    
//    UIButton *btn = [_footView viewWithTag:111];
//    if (_player.rate == 0) {
//        [btn setImage:[UIImage imageNamed:@"SJ_paly"] forState:UIControlStateNormal];
//    }else{
//        [btn setImage:[UIImage imageNamed:@"SJ_pause"] forState:UIControlStateNormal];
//    }
}
- (void)movieStalle:(NSNotification *)notic {
    NSLog(@"%@",NSStringFromSelector(_cmd));
}
- (void)backGroundPauseMoive {
    NSLog(@"%@",NSStringFromSelector(_cmd));
}

-(NSInteger)determineNetwork{
    NSInteger isExistenceNetwork = YES;
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    switch ([reach currentReachabilityStatus]) {
        case NotReachable:
            isExistenceNetwork = 0;
            break;
        case ReachableViaWiFi:
            isExistenceNetwork = 1;
            break;
        case ReachableViaWWAN:
            isExistenceNetwork = 2;
            break;
    }
    if (!isExistenceNetwork) {
        return 0;
    }
    return isExistenceNetwork;
}

//锁屏界面开启和监控远程控制事件
- (void)createRemoteCommandCenter{
    
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    //耳机线控的暂停/播放
    commandCenter.togglePlayPauseCommand.enabled = YES;
    __weak typeof(self) weakSelf = self;
    [commandCenter.togglePlayPauseCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        if (weakSelf.player.rate == 0) {
            [weakSelf play];
        }else {
            [weakSelf pause];
        }
        return MPRemoteCommandHandlerStatusSuccess;
    }];
    [commandCenter.pauseCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        [weakSelf pause];
        return MPRemoteCommandHandlerStatusSuccess;
    }];
    [commandCenter.stopCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        [weakSelf pause];
        return MPRemoteCommandHandlerStatusSuccess;
    }];
    [commandCenter.playCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        [weakSelf play];
        return MPRemoteCommandHandlerStatusSuccess;
    }];
    [commandCenter.previousTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        NSLog(@"上一首");
//        if (!weakSelf.isFirstMusic){
            [weakSelf lastPlay];
        [[ICMusicPlayManager sharedManager] playFormerMusic];
//        }
        return MPRemoteCommandHandlerStatusSuccess;
    }];
    [commandCenter.nextTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        NSLog(@"下一首");
//        if (!weakSelf.isLastMusic) {
//            [weakSelf nextPlay];
        [[ICMusicPlayManager sharedManager] playNextMusic];
//        }
        return MPRemoteCommandHandlerStatusSuccess;
    }];
    
    //在控制台拖动进度条调节进度
    [commandCenter.changePlaybackPositionCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
        MPChangePlaybackPositionCommandEvent * playbackPositionEvent = (MPChangePlaybackPositionCommandEvent *)event;
        [weakSelf seekToTime: playbackPositionEvent.positionTime  completionHandler:^(BOOL finished) {
        
        }];
        return MPRemoteCommandHandlerStatusSuccess;
    }];
}

//关闭远程控制中心
- (void)closeRemoteCommandCenter {
    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    [commandCenter.pauseCommand removeTarget:self];
    [commandCenter.playCommand removeTarget:self];
    [commandCenter.previousTrackCommand removeTarget:self];
    [commandCenter.nextTrackCommand removeTarget:self];
    [commandCenter.changePlaybackPositionCommand removeTarget:self];
    commandCenter = nil;
}

-(NSString *)GetdocumentsDirectory{
    NSArray*pathsss =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    return [pathsss objectAtIndex:0];
}

@end
